- 论坛徽章:
- 0
|
回复 2楼 星尘细雨 的帖子
是close
我是这样测的:
1。server起来,监听
2。client连上来
3。server accept,然后close
4。client sleep5秒(等server close socket)
5。client 发数据 --》没有抛异常
测试2:
1。server起来,监听
2。client连上来
3。server accept,然后recv
4。client 不发任何数据就close
5。server的recv返回,也没有抛异常
下面是源码
<server.py>
from socket import *
import sys, time
if __name__ == '__main__':
if len (sys.argv) != 2:
print "usage:", sys.argv[0], "port"
else:
sockobj = socket (AF_INET, SOCK_STREAM)
sockobj.bind( ('', int(sys.argv[1])) )
sockobj.listen (2)
while True :
connection, address = sockobj.accept ()
print 'Connection from address', address, 'at', time.ctime (time.time())
connection.close();
# while True:
# rcvd = connection.recv(100)
# if not rcvd: break
# print rcvd
# connection.close()
# print time.ctime (time.time())
<client.py>
from socket import *
import time
if __name__ == '__main__':
sockobj = socket (AF_INET, SOCK_STREAM)
sockobj.connect( ('localhost', 50007) )
time.sleep(5)
sockobj.send("hello")
sockobj.close()
print time.ctime (time.time()) |
|