package net.djpowell.liverepl.client;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.net.InetAddress;
import java.net.Socket;
import java.util.logging.Logger;

public class Console {

	private static String NEWLINE = System.getProperty("line.separator");
	
	public static void main(InetAddress host, int port) throws Exception {
		final BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
		final Writer cout = new OutputStreamWriter(System.out);
		Socket s = new Socket(host, port);
		try {
			final Reader sin = new InputStreamReader(s.getInputStream());
			final Writer sout = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));

			Thread ch = new Thread("ConsoleHandler") {
				@Override
				public void run() {
					try {
						for (;;) {
							// use line-based i/o for reading from the keyboard
							String line = cin.readLine();
							sout.write(line + NEWLINE);
							sout.flush();
						}
					} catch (IOException e) {
						TRC.fine(e.getMessage());
					}
				}
			};
			ch.start();

			Thread sh = new Thread("SocketHandler") {
				@Override
				public void run() {
					try {
						for (;;) {
							// use character based i/o for printing server responses
							char c = (char) sin.read();
							cout.write(c);
							cout.flush();
						}
					} catch (IOException e) {
						TRC.fine(e.getMessage());
					}
				}
			};
			sh.start();
			
			// block until both threads finish
			sh.join();
			ch.join();
		} finally {
			s.close();
		}
	}
	
	private static final Logger TRC = Logger.getLogger(Console.class.getName()); 

}

@@ -679,16 +679,63 @@
 %09%09try %7B%0A
+%09%09%09final Thread main = Thread.currentThread();%0A
 %09%09%09final
@@ -791,16 +791,16 @@
 eam());%0A
-
 %09%09%09final
@@ -1084,24 +1084,56 @@
 readLine();%0A
+%09%09%09%09%09%09%09if (line == null) break;%0A
 %09%09%09%09%09%09%09sout.
@@ -1239,32 +1239,73 @@
 .getMessage());%0A
+%09%09%09%09%09%7D finally %7B%0A%09%09%09%09%09%09main.interrupt();%0A
 %09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09
@@ -1498,16 +1498,72 @@
 sponses%0A
+%09%09%09%09%09%09%09int ic = sin.read();%0A%09%09%09%09%09%09%09if (ic == -1) break;%0A
 %09%09%09%09%09%09%09c
@@ -1577,26 +1577,18 @@
  (char) 
-sin.read()
+ic
 ;%0A%09%09%09%09%09%09
@@ -1691,24 +1691,65 @@
 Message());%0A
+%09%09%09%09%09%7D finally %7B%0A%09%09%09%09%09%09main.interrupt();%0A
 %09%09%09%09%09%7D%0A%09%09%09%09%7D
@@ -1772,18 +1772,17 @@
 rt();%0A%09%09
-%09
 %0A
+
 %09%09%09// bl
@@ -1811,16 +1811,26 @@
  finish%0A
+%09%09%09try %7B%0A%09
 %09%09%09sh.jo
@@ -1838,16 +1838,17 @@
 n();%0A%09%09%09
+%09
 ch.join(
@@ -1850,16 +1850,74 @@
 join();%0A
+%09%09%09%7D catch (InterruptedException e) %7B%0A%09%09%09%09s.close();%0A%09%09%09%7D%0A
 %09%09%7D fina

Abort on eof