Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@oconnor663
Created September 7, 2013 03:07
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/6472488 to your computer and use it in GitHub Desktop.
Save oconnor663/6472488 to your computer and use it in GitHub Desktop.
UDP test client
import sys
import socket
import json
import hashlib
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
for line in sys.stdin:
if line:
sock.sendto(line.strip().encode('utf8'), (UDP_IP, UDP_PORT))
reply = sock.recv(65536).decode('utf8')
print(reply)
checksum = json.loads(reply)["checksum"]
message = json.loads(reply)["message"]
mychecksum = hashlib.md5(message.encode('utf8')).hexdigest()
if checksum == mychecksum:
print('valid')
else:
print('invalid!!!', mychecksum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment