import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect the socket to the port where the server is listening
server_address = ('10.0.36.222', 5025)
print >>sys.stderr, '\nConnecting to %s port %s' % server_address
sock.connect(server_address)

try:
    
    # Send data
    message = 'This is the message.  It will be repeated.'
    print >>sys.stderr, 'Sending --> "%s"' % message
    sock.sendall(message)

    # Look for the response
    amount_received = 0
    amount_expected = len(message)
    
    while amount_received < amount_expected:
        data = sock.recv(128)
        amount_received += len(data)
        print >>sys.stderr, '\nReceived <-- "%s"' % data

finally:
    print >>sys.stderr, '\nClosing socket'
    sock.close()

