-
-
Save teocci/fb51bda66ea2dd5ac5ba02a337e448b4 to your computer and use it in GitHub Desktop.
a simple udp server (python code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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