Skip to content

Instantly share code, notes, and snippets.

@oconnor663
Created September 7, 2013 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oconnor663/6472493 to your computer and use it in GitHub Desktop.
Save oconnor663/6472493 to your computer and use it in GitHub Desktop.
UDP test server
import socket
import hashlib
import json
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(65536) # buffer size is 1024 bytes
message = data.decode('utf8')
checksum = hashlib.md5(data).hexdigest()
reply = json.dumps({"message": message, "checksum": checksum})
sock.sendto(reply.encode('utf8'), (addr[0], addr[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment