You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
527 B

11 months ago
# 接收机相当于本机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()