Created
December 30, 2013 04:04
-
-
Save studiawan/8177665 to your computer and use it in GitHub Desktop.
Simple object serialization server
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/env python | |
import socket | |
import pickle | |
import sys | |
# some definitions | |
SIZE = 1024 | |
# building socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind(('localhost', 5000)) | |
s.listen(5) | |
while 1: | |
try: | |
# receive connected client | |
client, client_address = s.accept() | |
# receive client message | |
while 1: | |
try: | |
message = client.recv(SIZE) | |
if not message: | |
break | |
# unpickle message and print it | |
message = pickle.loads(message) | |
print client_address, message | |
except(KeyboardInterrupt, SystemExit): | |
sys.exit(0) | |
except(KeyboardInterrupt, SystemExit): | |
sys.exit(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment