Skip to content

Instantly share code, notes, and snippets.

@edprince
Created July 23, 2014 14:50
Show Gist options
  • Save edprince/5a7c87771435b9631656 to your computer and use it in GitHub Desktop.
Save edprince/5a7c87771435b9631656 to your computer and use it in GitHub Desktop.
import socket
import sys
HOST = "127.0.0.1"
PORT = 30000
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print "Socket created"
except socket.error as msg:
print 'Failed to create socket. Error Code : ' + str(msg[0] + ' Message ' + msg[1])
sys.exit(0)
try:
s.bind((HOST, PORT))
except socket.error as msg:
print 'Bind failed'
sys.exit(0)
print 'Socket bind complete'
while True:
data, addr = s.recvfrom(1024)
# data = d[0]
# addr = d[1]
print "Received >", data
# if not data:
# break
# reply = 'OK..' + data
# s.sendto(reply, addr)
# print 'message[' + addr[0] + ':' + str(addr[1]) + '] - ' + data.strip()
# s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment