标签:res server send 服务 ddr 版本 客户端 pre int
服务端 import socket server = socket.socket(type=socket.SOCK_DGRAM) server.bind((‘127.0.0.1‘,8080)) while True: data, addr = server.recvfrom(1024) print(data.decode(‘utf-8‘)) msg = input(‘>>>:‘) server.sendto(msg.encode(‘utf-8‘),addr)
客户端 import socket client = socket.socket(type=socket.SOCK_DGRAM) server_address = (‘127.0.0.1‘,8080) while True: msg = input(‘>>>:‘) msg = ‘来自客户端1的消息:%s‘%msg client.sendto(msg.encode(‘utf-8‘),server_address) data, server_addr = client.recvfrom(1024) print(data.decode(‘utf-8‘))
import socket client = socket.socket(type=socket.SOCK_DGRAM) server_address = (‘127.0.0.1‘,8080) while True: msg = input(‘>>>:‘) msg = ‘来自客户端2的消息:%s‘%msg client.sendto(msg.encode(‘utf-8‘),server_address) data, server_addr = client.recvfrom(1024) print(data.decode(‘utf-8‘))
标签:res server send 服务 ddr 版本 客户端 pre int
原文地址:https://www.cnblogs.com/yangxinpython/p/11323647.html