Trigger mechanism: 1) Horizontal trigger, 2) edge trigger
IO multiplexing single-threaded implementation of the module: 1) Select (lowest efficiency), 2) poll;3) Epoll (best, nginx implementation). There are 3 types of modules under Linux, and only the Select module under Windows
Benefits of IO Multiplexing: Multiple connections can be monitored simultaneously
IO multiplexing Select module trigger mechanism: Horizontal Trigger
PS: Asynchronous: The whole process, can not have a hint of blocking
Client side:
import Socketsk = Socket.socket () Sk.connect (( " 127.0.0.1 ", 8801)) while TRUE:INP = input ("
>>>> " " Sk.sendall (bytes (INP, " UTF8 " )) Data = SK.RECV (1024) print (str (data,
Server side:
ImportSocketImportSelectsk=socket.socket () Sk.bind ("127.0.0.1", 8801)) Sk.listen (5) Inputs=[SK,] whiletrue:r,w,e=select.select (inputs,[],[],5) forObjinchR:#[SK,] ifobj==Sk:conn,add=obj.accept ()Print(conn) inputs.append (conn)Else: Data_byte=OBJ.RECV (1024) Print(Str (Data_byte,'UTF8')) InP=input ('Answer%s customer >>>'%inputs.index (obj)) obj.sendall (bytes (INP,'UTF8')) Print('>>', R)
Python-io multiplexing, select module