import socket
设置服务器的IP地址和端口
SERVER_IP = '127.0.0.1'
SERVER_PORT = 12345
创建一个socket对象
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
准备要发送的数据
message_to_send = "Hello, UDP Server!"
发送数据到服务器
client_socket.sendto(message_to_send.encode('utf-8'), (SERVER_IP, SERVER_PORT))
关闭socket连接
client_socket.close()