Good time to go to bed, tomorrow also to work ~ ~ Directly on the code, and then summarized
1 ImportThreading2 ImportOS3 ImportSocket4 5 6 defrecvprocess (Udp_socket, localaddrinfo):7 Print 'UDP Recver is up'8 while1:9data, peeraddr = Udp_socket.recvfrom (1024 )Ten ifdata = ='Local Exit' andLocaladdrinfo = =peeraddr: One Print 'Recvprocess was terminated!' A Break - #data = Raw_input () - Print '%s (Messagefrom%s:%d)'% (data, peeraddr[0], peeraddr[1] ) the - if __name__=='__main__': - #Create UDP Socekt -s =Socket.socket (socket.af_inet, socket. SOCK_DGRAM) + #Get Local Machine name -MyName =Socket.getfqdn (Socket.gethostname ()) +MYADDR =socket.gethostbyname (myname) AAddrinfo = (myaddr, 5060 ) at Printmyaddr - S.bind (addrinfo) - #Start the RECV process -THREADRECV = Threading. Thread (target = recvprocess, args =(S, addrinfo)) - Threadrecv.start () - while1: inval =raw_input () - ifval = ='Exit': toS.sendto ('Local Exit', Addrinfo) + Break -S.sendto (Val, ('192.168.3.36', 5060) ) the Print 'quit'
Python's humble version of a one-to-one chat tool, full duplex