// ChatClient.java SJ // three classes in the same file import java.io.*; import java.lang.*; import java.rmi.*; // main class, just starts listener and ui public class ChatClient { public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println("Usage: java ChatClient //host:port username"); return; } ChatClientThread net = new ChatClientThread(args[0], args[1]); net.start(); new ChatClientUI(net).start(); } // main() } // class ChatClient // thread to listen for the socket class ChatClientThread extends Thread { ChatInterface chat; String message; String remote; String userName; int myMessage; public ChatClientThread(String r, String u) { super(); userName = u; remote = r; myMessage = -1; } public void run() { try { chat = (ChatInterface) Naming.lookup ("rmi:" + remote + "/Chat"); /* clip */ } catch (Exception e) { System.err.println("ChatClient exception" + e); } } // run() // send message public void postMessage(String msg) { /* clip */ } public void quit() { /* clip */ } } // class ChatClientThread // User interface class ChatClientUI extends Thread { ChatClientThread net; public ChatClientUI(ChatClientThread n) { super(); net = n; } public void run() { String line = new String(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("UI ready"); while(true) { try { line = in.readLine(); } catch (IOException e) { System.err.println("input" + e); } if (line.indexOf("quit") != -1) { net.quit(); System.exit(0); } else net.postMessage(line); } } // run() } // class ChatClientUI