加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TOUClient.py 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
zhengyitian 提交于 2020-03-31 10:01 . x
import socket,select
from helpFunc import *
import uuid,json
mySalt = serviceSaltKey.encode()
from connClient import connClient
id = str(uuid.uuid1())
ports2 = []
gSalt = b''
salt_str = randomStringDigits()
while True:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
m = {'sign':id}
m['rate'] = con_minRate
m['pushAhead'] = con_pushAhead
m['packLimit'] = con_packLimit
m['salt'] = salt_str
gSalt = m['salt'].encode()
m['num'] = maxPortNum
j = json.dumps(m)
j = j.encode()
u ,s2 = makePack(j,mySalt)
sock.sendto(s2, (con_serverIp, servicePort))
r = select.select([sock],[],[],timeoutTime)
if r[0]==[]:
sock.close()
continue
j = sock.recv(recLen)
s2 = checkPackValid(j,u,mySalt)
if not s2:
sock.close()
continue
ports = []
st = structWrapper(s2)
for i in range(maxPortNum):
ports.append(st.readWord())
print ('server starts:',ports)
ports2 = ports
sock.close()
break
import time
from tornado.ioloop import IOLoop
serverListenPort = ports2
rate = con_minRate
pushAhead = con_pushAhead
packLimit = con_packLimit
salt = gSalt
clientListenIp = '0.0.0.0'
clientListenPort = 9999
time.sleep(1)
t = connClient(serverListenPort,salt,rate,pushAhead,packLimit,clientListenIp,clientListenPort)
IOLoop.instance().start()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化