import java.io.*;
import java.net.*;
import java.security.CodeSigner;
import java.util.Scanner;

public class MyTelnet {

  public static void main(String args[]) throws Exception {
    String host = args[0];
    int port = Integer.parseInt(args[1]);
    Socket socket = new Socket(host, port);
    InputStream in = socket.getInputStream();
    PrintStream out = new PrintStream(socket.getOutputStream());
    Scanner terminalScanner = new Scanner(System.in);

    Thread networkListenThread = new Thread() {
      public void run() {
        try {
          int b;
          while ((b = in.read()) != -1) {
            System.out.write(b);
            System.out.flush();
          }
          System.err.println("*** remote server closed the connection *** ");
        } catch (IOException e) {
          System.err.println(e);
        }
      }
    };
    networkListenThread.start();
    while (terminalScanner.hasNextLine()) {
      String line = terminalScanner.nextLine();
      out.print(line + "\r\n");
    }
    System.err.println("*** user closed the connection ***");
  }
}