import socket import threading def ip_port(): global address if len(address) < 2: ip = input('输入ip->>>') port = int(input('输入port->>')) address = (ip, port) return address def send(): while True: addr = ip_port() data = input().encode('gbk') user1.sendto(data, addr) def recv(): while True: global address msg, address = user1.recvfrom(1024) print(msg.decode('gbk')) if __name__ == '__main__': t_send = threading.Thread(target=send) t_recv = threading.Thread(target=recv) user1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) user1.bind(('192.168.48.1', 6899)) address = tuple() t_send.start() t_recv.start()
基于UDP协议写的全双工循环聊天
最新推荐文章于 2024-03-06 22:16:16 发布