python使用socket监听客户端发送文本内容,pythonsocket,下面是一个简单的代码,使
python使用socket监听客户端发送文本内容,pythonsocket,下面是一个简单的代码,使
下面是一个简单的代码,使用socket监听客户端发送的文本内容:
# To test it with netcat, start the script and execute:# # echo "Hello, cat." | ncat.exe 127.0.0.1 12345#import socketHOST = 'localhost' # use '' to expose to all networksPORT = 12345def incoming(host, port): """Open specified port and return file-like object""" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # set SOL_SOCKET.SO_REUSEADDR=1 to reuse the socket if # needed later without waiting for timeout (after it is # closed, for example) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((host, port)) sock.listen(0) # do not queue connections request, addr = sock.accept() return request.makefile('r', 0)# /-- network ---for line in incoming(HOST, PORT): print line,
相关内容
- python 控制语句 else,pythonelse,python中的else
- 两种python 判断网页编码的方法,python判断网页编码,这
- python字符串方法总结,python字符串总结,python的字符串模
- python 使用datetime模块timedelta实现日期时间相加,dateti
- python时间日期模块使用总结,python模块,python中关于时间
- python string to datetime datetime to string,pythondatetime,python日
- 访问需要HTTP Basic Authentication认证的资源的python实现,
- python设置socket的超时时间,pythonsocket超时,在使用urlli
- python卸载模块,python卸载,在python中如果不再
- python的is运算符,pythonis运算符,python的is运算符
评论关闭