代码是这样的 c的socket的连接,q是队列,数据接收到后会放入 q 给其他程序处理
具体问题就是这个settimeout会粘包,我发一次数据他三四次才拿的到
def recvTCPmsgs(q, c): # 用于接收 服务端 发送的数据
ind = 0
while True:
c.settimeout(10)
# print(c.gettimeout())
msg = c.recv(600000)
print('-------')
print('接收到的数据为:',len(msg))
print('-------')
q.put(msg)
ind += 1
print(ind)
# try:
# # time.sleep(2)
# msg = c.recv(600000) # try to receive 100 bytes
# # print('-------')
# c.settimeout(None)
# q.put(msg)
# except: # fail after 1 second of no activity
# print("没有数据了,关闭端口")
# q.put('没数据了')
# c.close()
# break