from socket import *
from threading import Thread
def send_msg(udp_socket: socket, dest_ip, dest_port):
while True:
send_data = input("请输入要发送的信息:")
udp_socket.sendto(send_data.encode("utf-8"), (dest_ip, dest_port))
def recv_msg(udp_socket: socket):
while True:
recv_data = udp_socket.recvfrom(1024)
print(recv_data[0].decode("utf-8"))
udp_socket = socket(AF_INET, SOCK_DGRAM)
udp_socket.bind(("", 8890))
dest_ip = input("请输入对方的ip:")
dest_port = int(input("请输入对方的port:"))
t_send = Thread(target=send_msg, args=(udp_socket, dest_ip, dest_port))
t_recv = Thread(target=recv_msg, args=(udp_socket, ))
t_send.start()
t_recv.start()