import java.io.*;
import java.net.*;
/*
 * The client program can send text lines to a server program.
 */
class LineClient {
    public static void main( String[] args ) {
        if ( args.length != 2 ) {
	    System.out.println("usage: java LineClient host port");
	    System.exit(1);
        }
	int port = 0;
	String host = null;
	try {
	    host = args[0];
	    port = Integer.parseInt( args[1] );
	}
	catch( NumberFormatException e ) {
	    System.out.println("bad port number");
	    System.exit(1);
	}

        try {
	    /* determine the address of the server and connect to it */
	    InetAddress server = InetAddress.getByName( host );
	    Socket sock = new Socket( server, port );
	    /* get the input stream */
	    InputStream in = sock.getInputStream();
	    /* get the output stream */
	    OutputStream out = sock.getOutputStream();
	    /* attach it to a print writer */
	    PrintWriter wr = new PrintWriter( out, true );
            BufferedReader rr =
                new BufferedReader(new InputStreamReader( in ));
	    /* get an input reader */
	    BufferedReader rd
	         = new BufferedReader( new InputStreamReader(System.in));
            
	    String line = null;
	    while ( (line=rd.readLine()) != null ) {
	        wr.println( line );
                wr.flush();
                System.out.println( rr.readLine() );
	    }
	    /* terminate the connection */
	    sock.close();
	}
	catch( UnknownHostException e ) {
	    System.out.println("bad host name");
	    System.exit(0);
	}
	catch( IOException e ) {
	    System.out.println("io error:" + e);
	    System.exit(0);
	}
    }
}
