UDP网络协议

#服务端
#导入模块
import  socket
#创建 socket对象
server=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
server.bind(('10.0.126.54',8080))
while True:
    data=server.recv(1024)
    print('客户端:',data.decode())
#客户端
#导入模块
import socket
#创建socket对象
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
while True:
    data=input("请输入:")
    client.sendto(data.encode(),("10.0.126.54",8080))

猜你喜欢

转载自blog.csdn.net/qq_42817166/article/details/81914919