#multiprocessing custom communication based on UDP protocolService side: fromMultiprocessingImportProcessImportSocketdefTask (server):#Communication Cycle whileTrue:data, Client_addr= Server.recvfrom (1024) Print('===>', data, client_addr) Server.sendto (Data.upper (), client_addr)if __name__=='__main__': Server= Socket.socket (socket.af_inet, socket. SOCK_DGRAM)#Datagram protocol-"UDPServer.bind (('127.0.0.1', 8080)) #data, client_addr = Server.recvfrom (1024x768)P=process (target=task,args= (server,))#Connecting LoopsP.start ()--------------------------------------------------------------------------------Client:Importsocketclient=socket.socket (Socket.af_inet,socket. SOCK_DGRAM)#Datagram protocol-"UDP whiletrue:msg=input ('>>:'). Strip ()#msg= "Client.sendto (Msg.encode ('Utf-8'),('127.0.0.1', 8080)) Data,server_addr=client.recvfrom (1024) Print(data) client.close ()
Python calls the Process class method (implementing server, client concurrency)-UDP protocol under the multiprocessing module