This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# 接收机,相当于本机(192.168.49.10,端口号为 5010)
import socket
import time
while True:
# 1.创建udp对象
sk = socket.socket(type=socket.SOCK_DGRAM)
# 2.收发数据的逻辑
# 发送数据
msg = input("请输入要发送的数据:")
# sendto( 二进制字节流 , ip端口号 )
sk.sendto(msg.encode(), ("127.0.0.1", 9000))
# 接受数据
msg, addr = sk.recvfrom(1024)
print(msg.decode())
print(addr)
time.sleep(1)
# 3.关闭连接
sk.close()