react-native TCPSocket
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了react-native TCPSocket相关的知识,希望对你有一定的参考价值。
参考技术A 安装react-native-tcp按照官网配置就可以,不明白的可以跟着以下步骤
1、yarn add react-native-tcp
2、react-native link react-native-tcp
3、yarn add rn-nodeify
4、把下面这句
添加到package.json里面如图所在位置后,然后在终端执行一下 yarn postinstall 即可:
5、别忘记加上这句
接着就可以复制以下内容尝试了
辅助查看TCP nodejs net 模块链接 : https://nodejs.org/api/net.html#netcreateconnection
Python TCPSocket
TCP套接字
TCPSockServer:
from socket import *
from time import ctime
BUFFSISE = 1024
HOST = ‘127.0.0.1‘
PORT = 10054
mySocket = socket(AF_INET, SOCK_STREAM, 0)
ADDR = (HOST, PORT)
mySocket.bind(ADDR)
mySocket.listen(5)
while True:
print("waiting for connection...\n")
clietSocket, clientAddr = mySocket.accept()
print("recive an request from: ", clientAddr)
while True:
data = clietSocket.recv(BUFFSISE).decode()
print("received data: %s" % data)
if not data:
break
clietSocket.send((‘[%s] %s‘ % (ctime(), data)).encode())
clietSocket.close()
mySocket.close()
TCPSockClient:
from socket import *
HOST = ‘127.0.0.1‘
PORT = 10054
ADDR = (HOST, PORT)
BUFFSIZE = 1024
mySocket = socket(AF_INET, SOCK_STREAM, 0)
mySocket.connect(ADDR)
while True:
data = input(">: ")
if not data:
break
mySocket.send(data.encode())
data = mySocket.recv(BUFFSIZE)
if not data:
break
print(data)
mySocket.close()
以上是关于react-native TCPSocket的主要内容,如果未能解决你的问题,请参考以下文章
在另一个 React-Native 库中使用 React-Native 库
React-Native + crypto:如何在 React-Native 中生成 HMAC?
React-native:如何在 React-native 中使用(和翻译)带有 jsx 的 typescript .tsx 文件?
React-Native 开发 在react-native 中 运用 redux
在解析模块`react-native/Libraries/Core/Devtools/getDevServer`时,发现了Haste包`react-native`