Created
December 30, 2013 04:04
-
-
Save studiawan/8177663 to your computer and use it in GitHub Desktop.
Simple object serialization client
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 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