import sys
from socket import *   # Only for demo!
import pickle

PORT = 2048           # Remote server port
ADDR = gethostname()  # Assume same machine

if len(sys.argv) == 3:
    PORT, ADDR = sys.argv[1:]

# Create socket object
sock = socket()  # Defaults to AF_INET and SOCK_STREAM

# Get remote server name and port
addr = (gethostbyname(ADDR), int(PORT)) 

# Connect to server
sock.connect(addr)

print "Starting transmission..."

# Create a local object and send via pickle
mylist = [0, gethostname()]
fo = sock.makefile(mode="wb")

for i in range(3):
    mylist[0] = i
    pickle.dump(mylist, fo, 2)

#pickle.dump("That's all folks!", fo, 2)

# Close socket once finished
print "Ending transmission..."

sock.close()
fo.close()
