Skip to content

Instantly share code, notes, and snippets.

@Averroes
Created April 10, 2015 17:10
Show Gist options
  • Select an option

  • Save Averroes/6adf312dbb4c71fdb6a8 to your computer and use it in GitHub Desktop.

Select an option

Save Averroes/6adf312dbb4c71fdb6a8 to your computer and use it in GitHub Desktop.
creating a udp server
from socket import socket, AF_INET, SOCK_DGRAM
import time
def time_server(address):
sock = socket(AF_INET, SOCK_DGRAM)
sock.bind(address)
while True:
msg, addr = sock.recvfrom(8192)
print('Got message from', addr)
resp = time.ctime()
sock.sendto(resp.encode('ascii'), addr)
if __name__ == '__main__':
time_server(('', 20000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment