udp_socket with thread to contect with each other

来源:互联网 发布:抢票软件 编辑:程序博客网 时间:2024/05/16 07:26
from threading import Threadfrom socket import *def sendinfo():    while True:        sendinfo = input('<<')        udpSocket.sendto(sendinfo.encode('utf-8'),adress)def recvinfo():    while True:        recvinfo = udpSocket.recvfrom(1024)        print("\r>>"+recvinfo[0].decode('utf-8')+'  '+str(recvinfo[1]))udpSocket = socket(AF_INET,SOCK_DGRAM)udpSocket.bind(('',4567))adress = ('ip',port)def main():    ts = Thread(target = sendinfo)    tr = Thread(target = recvinfo)    ts.start()    tr.start()    ts.join()    tr.join()if __name__ == '__main__':    main()