import socket

# 创建 UDP socket
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# 绑定地址和端口
HOST = "0.0.0.0"
PORT = 8888

server.bind((HOST, PORT))

print(f"UDP服务器正在监听 {HOST}:{PORT}")

while True:
    # 接收数据
    data, addr = server.recvfrom(1024)

    print(f"收到来自 {addr} 的消息: {data.decode()}")

    # 回复客户端
    reply = "服务器已收到"
    server.sendto(reply.encode(), addr)