from threading import Thread from socket import * updSocket = socket(AF_INET,SOCK_DGRAM) updSocket.bind(("",8000)) def recvData(): while True: recvMsg = updSocket.recvfrom(1024) print(">>%s:%s"%(recvMsg[1]),recvMsg[0]) def sendData(): sendinfo = input("<<") updSocket.sendto(sendinfo.encode("utf-8"),("192.168.1.9",8001)) print("\r\n>>%s:%s"%(sendinfo[1],sendinfo[0])) def main(): tr = Thread(target = recvData ) ts = Thread(target = sendData ) tr.start() ts.start() tr.join() ts.join() if __name__ == "__main__": main()