public interface ClientInterface extends java.rmi.Remote { public void showText(String s) throws java.rmi.RemoteException; } import java.io.*; public class Client extends java.rmi.server.UnicastRemoteObject implements ClientInterface { public static void main(String args[]) throws Exception { new Client(); } public synchronized void showText(String s) throws java.rmi.RemoteException { System.out.println(s); } public Client() throws Exception { ServerInterface server; server = (ServerInterface)java.rmi.Naming.lookup("//euclid.nmu.edu:5001/chat"); //java.rmi.server.UnicastRemoteObject.exportObject(c); server.register(this); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); while (2 == 2) { String text = stdin.readLine(); System.out.println(text); server.showText(text); } } } public interface ServerInterface extends java.rmi.Remote { public void showText(String s) throws java.rmi.RemoteException; public void register(ClientInterface i) throws java.rmi.RemoteException; } import java.io.*; public class Server extends java.rmi.server.UnicastRemoteObject implements ServerInterface { ClientInterface client; public static void main(String[] args) throws Exception { new Server(); } public Server() throws Exception { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.setSecurityManager(new java.rmi.RMISecurityManager()); java.rmi.registry.LocateRegistry.createRegistry(5001); java.rmi.Naming.rebind("rmi://:5001/chat", this); while (2 == 2) { String text = stdin.readLine(); if (client != null) client.showText(text); else System.out.println("No Client"); } } public void register(ClientInterface i) throws java.rmi.RemoteException { System.out.println("Client registered"); client = i; } public synchronized void showText(String s) throws java.rmi.RemoteException { System.out.println(s); } }