#!/usr/bin/env python

# simple illustration client/server pair; client program sends a string
# to server, which echoes it back to the client (in multiple copies),
# and the latter prints to the screen

# this is the client

import cgi
import cgitb
import socket
import sys

cgitb.enable()

# create a socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# connect to server
host = '50.57.76.50'#sys.argv[1] # server address
port = 998#int(sys.argv[2]) # server port
s.connect((host, port))

s.send(sys.argv[1]) #(sys.argv[3]) # send test string

# read echo
i = 0
while(1):
	data = s.recv(1000000) # read up to 1000000 bytes
	i += 1
	if (i < 5): # look only at the first part of the message
		print data
		if not data: # if end of data, leave loop
			break
		print 'received', len(data), 'bytes'

# close the connection
s.close()