1. Server and multi-client communication
1 ImportSocket2 #to create a socket for a TCP socket3SK =Socket.socket ()4 #Bind5Sk.bind (('127.0.0.1', 8080))6 #Monitor7Sk.listen (5)8 #Waiting for connection9 while1:Tenconn, addr =sk.accept () One while1: Amsg_s = input ('>>>') -Conn.send (Msg_s.encode ('Utf-8')) - ifmsg_s = ='Q': the Break -Msg_r = Conn.recv (1024x768). Decode ('Utf-8') - ifMsg_r = ='Q': - Break + Print(Msg_r) - conn.close () + ASk.close ()
tcp_ server-side
1 ImportSocket2 3SK =Socket.socket ()4 5Sk.connect (('127.0.0.1', 8080))6 7 8 while1:9Msg_r = Sk.recv (1024x768). Decode ('Utf-8')Ten ifMsg_r = ='Q': One Break A Print(Msg_r) -msg_s = input ('>>>') -Sk.send (Msg_s.encode ('Utf-8')) the ifmsg_s = ='Q': - Break - -Sk.close ()
TCP_ Client
2. UDP protocol
3, Pycharm printing with color output
4, the mechanism of time synchronization
Python full stack __ Server and multi-client communication, UDP protocol, Pycharm printing with color output, time synchronization mechanism