在测试中发现,如果发送端一次性发送大量的数据,然后关闭session,接收端来不及处理,就会发出TCP ZeroWindow报文
Recv 脚本:
# -*- coding:utf-8 -*-'''创建服务器端程序,用来接收客户端传进的数据'''from socket import *from time import ctimeimport timeimport ConfigParserdef server(): HOST = '172.21.35.81' PORT = 10522 ADDR = (HOST,PORT) server_socket = socket(AF_INET,SOCK_STREAM) server_socket.bind(ADDR) server_socket.listen(5) '''Config information''' cfg = ConfigParser.ConfigParser() cfg.read("Config.ini") src = cfg.get("FILE", "RECV_FILE") while True: print 'Waiting for connecting ......' tcpclientsocket,addr = server_socket.accept() print 'Connected by ',addr recvfile = open(src, 'wb') while True: data = tcpclientsocket.recv(1) if not data: break else: recvfile.write(data) #print data time.sleep(5) recvfile.close() print 'Received Data Success\n' tcpclientsocket.close() server_socket.close()server()
Send 脚本:
# -*- coding:utf-8 -*-'''创建客户端程序,向服务器传递数据'''from socket import *import sysimport osimport ConfigParserfrom subprocess import *'''Config information'''cfg = ConfigParser.ConfigParser()cfg.read("Config.ini")src = cfg.get("FILE", "SEND_FILE")#def client():HOST = '127.0.0.1'PORT = 10521length = os.path.getsize(src)f1 = open(src, 'rb')countent = f1.read()f1.close() clientsocket = socket(AF_INET,SOCK_STREAM)clientsocket.connect((HOST, PORT))clientsocket.send(countent)clientsocket.close()print 'Send Data OK'
测试配置文件,需要在当前目录放一个比较大的文件作为发送数据:(configure.ini)
[FILE]SEND_FILE = welcome.wavRECV_FILE = save_welcome.wav