udp_client.py 294 B

1234567891011121314
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import socket
  4. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  5. for data in [b'Michael', b'Tracy', b'Sarah']:
  6. # 发送数据:
  7. s.sendto(data, ('127.0.0.1', 9999))
  8. # 接收数据:
  9. print(s.recv(1024).decode('utf-8'))
  10. s.close()