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超时的更多相关文章
- python socket 超时设置 errno10054
python socket.error: [Errno 10054] 远程主机强迫关闭了一个现有的连接.问题解决方案: 前几天使用python读取网页.因为对一个网站大量的使用urlopen操作,所以 ...
- [转] python 远程主机强迫关闭了一个现有的连接 socket 超时设置 errno 10054
python socket.error: [Errno 10054] 远程主机强迫关闭了一个现有的连接.问题解决方案: 前几天使用python读取网页.因为对一个网站大量的使用urlopen操作,所以 ...
- python有超时的windows系统时间设置代码
手边的笔记本用久了,cmos电池可能又没电了.每次开机时间都不对,导致访问一些有https的网页会出现警告信息. 于是找了找通过python脚本设置系统时间的方法,发现了两种,其一是调用socket直 ...
- python socket.error: [Errno 10054] 解决方法
我用的是python2.7 我搜网上10054错误解决方法的时候发现,大部分文章都是以python3为基础的,对于python2不适用. python socket.error: [Errno 1 ...
- PYTHON SOCKET编程简介
原文地址: PYTHON SOCKET编程详细介绍 Python 提供了两个基本的 socket 模块. 第一个是 Socket,它提供了标准的 BSD Sockets API. 第二个是 Soc ...
- Python Socket网络编程详解
Socket 简介 socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求. s ...
- Python socket 基础(Server) - Foundations of Python Socket
Python socket 基础 Server - Foundations of Python Socket 通过 python socket 模块建立一个提供 TCP 链接服务的 server 可分 ...
- Python socket 基础(Client) - Foundations of Python Socket
Python socket 基础- Foundations of Python Socket 建立socket - establish socket import socket s = socket. ...
- Python Socket 编程——聊天室示例程序
上一篇 我们学习了简单的 Python TCP Socket 编程,通过分别写服务端和客户端的代码了解基本的 Python Socket 编程模型.本文再通过一个例子来加强一下对 Socket 编程的 ...
随机推荐
- 用.NET从外部dwg文件导入块
翻译并引自Kean's blog的两篇文章: http://through-the-interface.typepad.com/through_the_interface/2006/08/import ...
- POSTGRES与JDBC对照
POSTGRES与JDBC对照 未经验证,仅供参考.
- 粗略了解struts2
花了半天的时间再把struts2详细拟了一遍,之前用习惯了servlet加jsp,再看struts2的时候终于明白为什么大家都愿意学,以人类天生的惰性,要让他们愿意去学习一个新的东西,这东西一定可以让 ...
- 深入理解javascript--笔记
书写可维护的代码 1,最小全局变量 在js中不用声明变量就可以直接使用,因此注意不要没有声明就使用.(无意中创建的全局变量)比如使用任务链进行var声明.var a=b=12;正确写法为var ...
- 浅谈Runloop
RunLoop 是 iOS 和 OS X 开发中非常基础的一个概念,这篇文章将从 CFRunLoop 的源码入手,介绍 RunLoop 的概念以及底层实现原理.之后会介绍一下在 iOS 中,苹果是如何 ...
- linux按键驱动之poll
上一节应用程序的死循环里的读函数是一直在读的:在实际的应用场所里,有没有那么一种情况,偶尔有数据.偶尔没有数据,答案当然是有的.-->poll机制:Poll机制实现的是一定时间如果没有按键的话就 ...
- CE创建进程和线程
创建进程: HWND hWnd = NULL; PROCESS_INFORMATION pi = {}; if(NULL==hWnd) { hWnd=FindWindow(NULL,_T(" ...
- Python检测IP合法 是否为公网IP
判断IP 格式是否正确 def check_value(self, ipaddr): '''检查IP是否合法 :param ipaddr: string :return True ''' addr=i ...
- Codeforces Round #341 Div.2 C. Wet Shark and Flowers
题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里 ...
- Python3 之 import 和 当前目录
环境: Python-3.4.3 Web.py-0.37 安装 web.py 的时候,提示 ImportError: No module named 'utils' 看看源码,setup.py,有这么 ...