Skip to content

Instantly share code, notes, and snippets.

@studiawan
Created December 30, 2013 04:04
Show Gist options
  • Save studiawan/8177665 to your computer and use it in GitHub Desktop.
Save studiawan/8177665 to your computer and use it in GitHub Desktop.
Simple object serialization server
#!/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