import socket
import threading
import time
server_ip = '127.0.0.1'
server_port = 3012
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # socket.SOCK_DGRAM代表是UDP通信
def send(content):
content = content.encode('utf-8')
global s
s.sendto(content, (server_ip, server_port))
def recive():
global s
while True:
data, addr = s.recvfrom(1024)
print(str(data))
time.sleep(1)
if __name__ == "__main__":
threading.Thread(target=recive)
while True:
content = input("请输入指令:")
send(content)
用udp通信发送指令
最新推荐文章于 2024-07-13 15:30:33 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)