Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a simple udp server (python code)
#! /usr/bin/python
# a simple udp server
import socket, traceback
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("127.0.0.1",12345))
while 1:
try:
message, address = s.recvfrom(1024)
print "Got data from", address
print message
s.sendto(message, address)
except (KeyboardInterrupt, SystemExit):
raise
except:
traceback.print_exc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment