Skip to content

Instantly share code, notes, and snippets.

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

  • Save Averroes/1f0376b7e201eea7c1c8 to your computer and use it in GitHub Desktop.

Select an option

Save Averroes/1f0376b7e201eea7c1c8 to your computer and use it in GitHub Desktop.
creating a udp server
from socketserver import BaseRequestHandler, UDPServer
import time
class TimeHandler(BaseRequestHandler):
def handle(self):
print('Got connection from', self.client_address)
# Get message and client socket
msg, sock = self.request
resp = time.ctime()
sock.sendto(resp.encode('ascii'), self.client_address)
if __name__ == '__main__':
serv = UDPServer(('', 20000), TimeHandler)
serv.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment