Python socket超时
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python socket超时相关的知识,希望对你有一定的参考价值。
#server.py import socket s=socket.socket() s.bind((‘127.0.0.1‘,2000)) s.listen(5) while 1: cs,address=s.accept() cs.settimeout(5) print ‘got cinnected from‘,address cs.send(‘hello I am server,weclome‘) ra=cs.recv(512) print ra cs.close()
当连接建立后,没有动作
got cinnected from (‘127.0.0.1‘, 60701)
Traceback (most recent call last):
File "server.py", line 10, in <module>
ra=cs.recv(512)
socket.timeout: timed out
#client.py import socket s=socket.socket() s.connect((‘127.0.0.1‘,2000)) #s.sendall(‘hello server!‘) data=s.recv(512) print ‘the data received is\n ‘,data #s.send(‘hihi I am client‘) raw_input() s.close()
输出
the data received is
hello I am server,weclome
Python初学,如有错误,欢迎评论指出,不甚感激。
以上是关于Python socket超时的主要内容,如果未能解决你的问题,请参考以下文章