现在的位置: 首页 > 综合 > 正文

python socket Select模型

2018年03月22日 ⁄ 综合 ⁄ 共 651字 ⁄ 字号 评论关闭

import socket
import sys
import socket
import select
        
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(('192.168.1.103',21152))

print("Connected Ok!")

while 1:
 
    infds,outfds,errfds = select.select([s],[],[s],0.05)
    if len(infds):
        data = s.recv(4096)
        if not len(data):
            print("\r Remote end closed connection;exiting.")
            break;
        sys.stdout.write("\rReceived:"+data)
        sys.stdout.flush()
    if len(errfds):
        print("\rProblem occurred;exiting.")
        sys.exit(0)

    

编译通过 ,接受收据正常

Connected Ok!
Wed Apr 16 00:22:24 2014

Wed Apr 16 00:22:29 2014

Wed Apr 16 00:22:39 2014

Wed Apr 16 00:22:44 2014

Wed Apr 16 00:22:49 2014

Wed Apr 16 00:22:54 2014

Wed Apr 16 00:22:59 2014

Wed Apr 16 00:23:04 2014

抱歉!评论已关闭.