"""
Author : Semih Onay, semih.onay@bilgiedu.net

Connect to given host and port, then send lines user enters to server
and display what it receives from server to the user.
"""

import sys, socket

if len(sys.argv)<2:
    print "Usage:"
    print sys.argv[0]," hostname port"
    sys.exit(0)
hostname = sys.argv[1]
port = int(sys.argv[2])

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((hostname, port))
print "Connected to ", hostname
print "type 'quit' to end session"
inp = raw_input("> ")
while inp !="quit":
    sock.send(inp)
    data = sock.recv(1024)
    print 'Received:', data
    inp = raw_input("> ")
sock.close()
print "Goodbye"

