import java.rmi.*; import java.applet.*; import java.awt.*; import java.awt.event.*; import java.rmi.registry.*; import java.net.InetAddress; import java.util.Vector; /** *This is the applet that is launched as a client and contains a field for *Entering the message and a field for displaying all users currently registerd */ public class ClientStarter extends Applet { PopupServerInterface server; PopupClientImpl client ; TextArea ta; TextArea userlist; /** * Applet init, * Gets the registry running on the client and binds an instace of * PopupClientImpl to it. * It then looks up the server and registers itself there so that other * clients can know another client has come up. */ public void init(){ try{ LocateRegistry.createRegistry(1099); client =new PopupClientImpl(); Naming.rebind("/ClientPopup",client); System.out.println("Client bound"); server =(PopupServerInterface)Naming.lookup("rmi://" +getCodeBase().getHost()+":5000/ServerPop"); server.addUser((PopupClientInterface)client); System.out.println("Client registered on server"); }catch(Exception e){ System.out.println(e); } } /** * The AWT part creates the two text areas and adds the button * with the buttons event handler in an anonymous inner class. * It queries the server object for information about all the users * and displays that informaion in one text area. */ public void start(){ try{ userlist = new TextArea(10,12); Vector v = server.getUsers(); /* Query each object in the vector which is of type PopupClientInterface for some informaion.An Ip address in our case. Please note that this does not mean tha the applet is contacting the other applets directly ! It is through the server objects reference. */ for(int i=0;i