echo.py 444 B

123456789101112131415161718
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import socket
  4. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  5. server_address = '0.0.0.0'
  6. server_port = 1234
  7. server = (server_address, server_port)
  8. sock.bind(server)
  9. print("Listening on " + server_address + ":" + str(server_port))
  10. while True:
  11. payload, client_address = sock.recvfrom(1)
  12. print("Echoing data back to " + str(client_address))
  13. sent = sock.sendto(payload, client_address)