import javax.imageio.*;
import java.awt.image.*;
import java.awt.event.*;
import java.awt.*;
import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;
import java.lang.management.*;
import java.lang.reflect.*;
import java.net.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.util.List;
import java.util.zip.*;
import java.util.*;


public class main {
  public static void main(String[] args) throws Exception {
    telnetFromConsoleTo("second.tinybrain.de", 4999);
  }

static void telnetFromConsoleTo(String host, int port) {
  final DialogIO io = talkTo(host, port);
  
  // output
  Thread _t_0 = new Thread() {
public void run() {
try {

    String line;
    while ((line = readLine()) != null)
      io.sendLine(line);
  } catch (Exception _e) {
  throw _e instanceof RuntimeException ? (RuntimeException) _e : new RuntimeException(_e); } }
};
_t_0.start();
  
  // input
  while (io.isStillConnected()) {
    if (io.waitForLine()) {
      String line = io.readLineNoBlock();
      print("> " + line);
    }
  }
  
  print();
  print("[logout]");
}


  static abstract class DialogIO {
    abstract boolean isStillConnected();
    abstract String readLineNoBlock();
    abstract boolean waitForLine();
    abstract void sendLine(String line);
    abstract boolean isLocalConnection();
    abstract Socket getSocket();
  }
  
  static abstract class DialogHandler {
    abstract void run(DialogIO io);
  } // DialogIO
  
static DialogIO talkTo(String ip, int port) { try {
 
  print("Talking to " + ip + ":" + port);
  final Socket s = new Socket(ip, port);    

  final Writer w = new OutputStreamWriter(s.getOutputStream(), "UTF-8");
  final BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream(), "UTF-8"));
  return new DialogIO() {
    String line;
    boolean buff;
    
    boolean isLocalConnection() {
      return s.getInetAddress().isLoopbackAddress();
    }
    
    boolean isStillConnected() {
      return !(buff || s.isClosed());
    }
    
    String readLineNoBlock() {
      String l = line;
      line = null;
      return l;
    }
    
    boolean waitForLine() { try {
 
      if (line != null) return true;
      //print("Readline");
      line = in.readLine();
      //print("Readline done: " + line);
      if (line == null) buff = true;
      return line != null;
    
} catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}
    
    void sendLine(String line) { try {
 
      w.write(line + "\n");
      w.flush();
    
} catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}
    
    void close() { try {
 
      s.close();
    
} catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}
    
    Socket getSocket() {
      return s;
    }
  };

} catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}

static BufferedReader readLine_reader;

static String readLine() { try {
 
  if (readLine_reader == null)
    readLine_reader = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
  String s = readLine_reader.readLine();
  if (s != null)
    print(s);
  return s;

} catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}

static void print() {
  System.out.println();
}

static void print(Object o) {
  System.out.println(o);
}

static void print(long i) {
  System.out.println(i);
}
}