Once the client and server objects are ready, let's write some code to get these objects in place.
Two small programs that start off the process on the server and the client respectively are called ServerStarter and ClientStarter.
Creates an instance of our PopupServerImpl and binds it to the registry
Waits for the any of the clients or the console to transmit a message to all other clients
The registry can be started by independently invoking the registry from the prompt (by launching rmiregisrty.exe) or from within the code like this:
public static void main(String args[]){
LocateRegistry.createRegistry(5000);
ServerImpl serverobj = new SevrerImpl();
Naming.rebind("//:5000/ServerPop" , serverobj);
}
That's all it takes for the server to bind the object to the registry.
The rest of the code puts the server in a loop and waits for a message to be typed on the console by the admin to be sent to all users who are logged on.
BufferedReader br = new BufferReader( new InputStreamReader( System.in));
while(true){
String message = br.readLine();
Serverobj.sendMessage(message);
}
Sameer Tyagi is a Software Engineer with several years of programming experience in iNet application development and has conducted multiple training workshops in Java. Besides holding an Engineering degree in Electronics he is a Sun Certified Java 1.1 Programmer.
Email: sameertyagi@usa.net
JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for
Windows 95, 98, ME, NT, 2000 and XP. It's designed to
automatically optimize your Windows settings, boosting your
Internet connection up to 200%.
Blackmail Applet
This applet prints out text that looks like letters cut out of a
newspaper. You can specify the text, the width and height of the
applet and the delay after each letter. Future versions will
have more parameters.
While surveys suggest that small businesses aren't prepared for ever-present security dangers, this Boston-area printer has maintained a pristine operation since a scare six years ago.