#-*-Coding:utf-8-*-
# python:2.x
__author__ = ' Administrator '
# function: A notification that waits for input or the output channel is ready
"""
Allows access to specific platform I/O monitoring functions, the most portable interface is the POSIX function Select ()
unix and windwods " Span style= "font-family: the song Body;" > this 2 A function, this module can implement asynchronous communication, select poll () and select (), select () The prototype is (Rlist,wlist,xlist[,timeout])
Rlist waits for the object to be read,wlist waits for the final object , xlist waits for the exception object, the last optional object, specifies the wait time, the unit is s, The Select () method returns the value of the prepared object is ternary, if No object is ready in timeout time, then the return value is empty list
"""
#select Server
From socket Import *
Server=socket (Af_inet,sock_stream)
Server.setsockopt (sol_socket,so_reuseaddr,1) #socket. setsockopt (level, optname, value)
#Set the value of the given socket option (see the Unix manual page setsockopt (2)).
# The needed symbolic constants is defined in the socket module (so_* etc). The value can be a integer or a string representing a buffer.
# in the latter case it's up to
# The caller to ensure this string contains the proper bits (see the optional built-in module
# struct for a-to-encode C structures as strings).
Server.bind ((' ', 10000))
Inputs=[server]
From select Import *
While True:
Re1,ws,es=select (inputs,[],[])
For R in Re1:
If r in server:
Clientsock,clientaddr=r.accept ()
Inputs.append (Clientsock)
Else
DATA=R.RECV (1024)
If not data:
Inputs.remove (R)
Else
Print data
#-*-Coding:utf-8-*-
# python:2.x
__author__ = ' Administrator '
# Client
From socket Import *
Host= ' 127.0.0.1 '
port=10000
S=socket (Af_inet,sock_stream)
S.connect ((Host,port))
S.send (' Hello world! ')
S.close ()
Python uses select for asynchronous communication 1