sock = new Socket("localhost", Chat.PORTNUM);
is = new BufferedReader(new InputStreamReader(sock.getInputStream()));
pw = new PrintWriter(sock.getOutputStream(), true);
cons = new BufferedReader(new InputStreamReader(System.in));
// Construct and start the reader: from server to stdout.
// Make a Thread to avoid lockups.
new Thread() {
public void run() {
setName("socket reader thread");
System.out.println("Starting " + getName());
System.out.flush();
String line;
try {
// reader thread blocks here
while ((line = is.readLine()) != null) {
System.out.println(line);
System.out.flush();
}
} catch (IOException ex) {
System.err.println("Read error on socket: " + ex);
return;
}
}
}.start();