您的位置:首页 > 编程语言 > Python开发

python socket Select模型

2014-04-16 00:46 309 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python socket select