我正在使用select.select()从2台服务器获取数据,但是在服务器端断开连接时不知道如何重新连接。
我知道闭合的套接字不是异常(错误)情况。并且在断开连接时未在读取列表(rlist)中获得0字节。
我的代码
Nport1_ip_port = ('192.168.127.88',4001)
Nport2_ip_port = ('192.168.127.88',4002)
sock1 = socket.socket()
sock2 = socket.socket()
sock1.connect(Nport1_ip_port)
sock2.connect(Nport2_ip_port)
while 1:
rlist, wlist, elist = select.select( [sock1, sock2], [], [])
for sock in rlist:
if sock1 == sock:
recvdata, addr = sock.recvfrom(1024)
print "received sock1:"+str(recvdata)
if sock2 == sock:
recvdata, addr = sock.recvfrom(1024)
print "received sock2:"+str(recvdata)
服务器端断开连接时如何重新连接?