码迷,mamicode.com
首页 > 编程语言 > 详细

Python socket超时

时间:2016-02-23 20:36:43      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

#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超时

标签:

原文地址:http://www.cnblogs.com/dream-for/p/5210933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!