Discuss / Python / 20180608

20180608

Topic source

Gday小海狮

#1 Created at ... [Delete] [Delete and Lock User]

udp_client.py import socket s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) for data in [b'Micheal',b'Tracy',b'Sarah']: s.sendto(data,('127.0.0.1',9999)) print(s.recv(1024).decode('utf-8')) s.close()

udp.server.py import socket s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) s.bind(('127.0.0.1',9999)) print('Bind UDP on 9999...') while True: data,addr = s.recvfrom(1024) print('Received from %s:%s.' % addr) s.sendto(b'Hello, %s' % data, addr)


  • 1

Reply