Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Abort on eof
  • Loading branch information
djpowell committed Oct 18, 2009
1 parent 516a036 commit 4ee50bd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions liverepl-agent/src/net/djpowell/liverepl/client/Console.java
Expand Up @@ -20,6 +20,7 @@ public static void main(InetAddress host, int port) throws Exception {
final Writer cout = new OutputStreamWriter(System.out);
Socket s = new Socket(host, port);
try {
final Thread main = Thread.currentThread();
final Reader sin = new InputStreamReader(s.getInputStream());
final Writer sout = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));

Expand All @@ -30,11 +31,14 @@ public void run() {
for (;;) {
// use line-based i/o for reading from the keyboard
String line = cin.readLine();
if (line == null) break;
sout.write(line + NEWLINE);
sout.flush();
}
} catch (IOException e) {
TRC.fine(e.getMessage());
} finally {
main.interrupt();
}
}
};
Expand All @@ -46,20 +50,28 @@ public void run() {
try {
for (;;) {
// use character based i/o for printing server responses
char c = (char) sin.read();
int ic = sin.read();
if (ic == -1) break;
char c = (char) ic;
cout.write(c);
cout.flush();
}
} catch (IOException e) {
TRC.fine(e.getMessage());
} finally {
main.interrupt();
}
}
};
sh.start();

// block until both threads finish
sh.join();
ch.join();
try {
sh.join();
ch.join();
} catch (InterruptedException e) {
s.close();
}
} finally {
s.close();
}
Expand Down

0 comments on commit 4ee50bd

Please sign in to comment.