from threading import Thread
from 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()
udp_socket with thread to contect with each other
最新推荐文章于 2024-05-16 00:36:30 发布