!747 !1000868 // dialogHandler { m { static int chatPort = 9751; // just any number, but must match the server's number. static S programID; // filled by JavaX static abstract class DialogIO { abstract boolean isStillConnected(); abstract String readLineNoBlock(); abstract boolean waitForLine(); abstract void sendLine(String line); abstract void close(); } p { installHelloMessage(programID + " - Chat client"); startChatServerIfNotUp(); waitForChatServer(); final Socket s = new Socket("localhost", chatPort); print("connect"); final Writer w = new OutputStreamWriter(s.getOutputStream(), "UTF-8"); final BufferedReader in = new BufferedReader( new InputStreamReader(s.getInputStream(), "UTF-8")); DialogIO io = new DialogIO() { S line; boolean buff; boolean isStillConnected() { return !(buff || s.isClosed()); } String readLineNoBlock() { S l = line; line = null; return l; } boolean waitForLine() ctex { if (line != null) return true; print("Readline"); line = in.readLine(); print("Readline done: " + line); if (line == null) buff = true; return line != null; } void sendLine(String line) ctex { w.write(line + "\n"); w.flush(); } void close() ctex { s.close(); } }; //io.waitForLine(); io.sendLine("hello chat"); print("Sent line."); io.close(); print("Closed."); } }