Skip to content

Instantly share code, notes, and snippets.

@studiawan
Created December 30, 2013 04:04
Show Gist options
  • Save studiawan/8177663 to your computer and use it in GitHub Desktop.
Save studiawan/8177663 to your computer and use it in GitHub Desktop.
Simple object serialization client
#!/usr/bin/env python
import socket
import time
import sys
import pickle
def now():
return time.asctime(time.localtime(time.time()))
# building socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 5000))
while 1:
# infinite send pickled message
try:
# arranging message
msg = []
msg.append("Hi Server")
msg.append(now())
# pickling message
msg = pickle.dumps(msg)
s.send(msg)
time.sleep(1)
# exception
except(KeyboardInterrupt, SystemExit):
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment