python从网络端口读取文本数据,,# To test it
文章由Byrx.net分享于2019-03-23 05:03:21
python从网络端口读取文本数据,,# To test it
# 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常用字典操作范例,python字典范例,# experiment
- python操作sqlite3数据库完全代码,pythonsqlite3,None
- python对MySqldb模块的简单封装代码,pythonmysqldb封装,Non
- python实现线程池,python线程池,python实现线程池原
- 遗传算法的神经网络python实现代码,神经网络python,遗传
- python之花瓣美女下载,python花瓣美女,作者:vpoet日期:大
- Python 发送带附件的email,pythonemail,None
- python图片小爬虫,,import re i
- python给图片右上角加上红色的数字,,from PIL imp
- python改变图片尺寸,,from PIL imp
评论关闭