How to make an RMI server multi-client program without registerting clients




I have a RMI server which a number of clients connect to. When a client registers a change, the server reacts and instructs all clients to make a change.

I have been looking into a number of hello world RMI examples, but none of them addresses how to persist a connection back to the client from the server.

What i would like to achieve is something along these lines: Server is registered on the rmiregistry. Client 1 connects to the server and calls a method on the server. Client 2 connects to the server and calls a method on the server. The server sends the change from client2 to client1.

Java rmi example program with code - SlideShare
15 Mar 2013 ... Steps to run this programs: First of all put these four programs insidebin folder of
JDK. As an example suppose our JDK folder isinside java ...
http://www.slideshare.net/java2all/java-rmi-example-program-with-code

How does one achieve this without registering every client as a server?

EDIT: After looking at a couple of excellent ansvers (flatter flatter) i am running into the following exception java.rmi.StubNotFoundException: Stub class not found: thegame.connectivity.GameClient_Stub; nested exception is:

java.lang.ClassNotFoundException: thegame.connectivity.GameClient_Stub at sun.rmi.server.Util.createStub(Util.java:292) at sun.rmi.server.Util.createProxy(Util.java:140) at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:196) at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:310) at java.rmi.server.UnicastRemoteObject.exportObject(UnicastRemoteObject.java:237) at thegame.connectivity.GameClient.bind(GameClient.java:37) at thegame.connectivity.GameClient.run(GameClient.java:51) at thegame.connectivity.GameClient.main(GameClient.java:29) Caused by: java.lang.ClassNotFoundException: thegame.connectivity.GameClient_Stub at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at sun.rmi.server.Util.createStub(Util.java:286) ... 7 more

On this class

public class GameClient extends Thread implements Remote, Client, ModelChangeListener<Client>{ private static final long serialVersionUID = -394039736555035873L; protected Queue<GameModelEvent> queue = new ConcurrentLinkedQueue<GameModelEvent>(); public GameClient(){ } public static void main(String[] args){ GameClient client = new GameClient(); client.run(); } protected void bind(){ System.setProperty("java.rmi.server.codebase","file:bin/"); try { Registry registry = LocateRegistry.getRegistry(); Client c = (Client)UnicastRemoteObject.exportObject(this); Server stub = (Server) registry.lookup("Server"); stub.registerClient(c); } catch (RemoteException | NotBoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void run() { super.run(); bind(); while(!Thread.interrupted()){ System.out.print("."); GameModelEvent event = queue.poll(); while(event != null){ System.out.println(event); event = queue.poll(); } try { Thread.sleep(100); } catch (InterruptedException e) { return; } } } ...

It works well when i comment out the UnicatRemoteObject and just pass null as a parameter. So there is a connection and everything is running. But no stub... Commenting out the codebase has no effect either. The codebase works fine on the server.

Creating a Client Program (The Java™ Tutorials > RMI)
This RMI Java tutorial describes the Java RMI system. It walks ... Two separate
classes make up the client in our example. ... Finally, the program prints the result
.
https://docs.oracle.com/javase/tutorial/rmi/client.html

Any ideas on what is wrong?







http://stackoverflow.com

Blood Component Therapy
Blood Component Therapy Fresh Frozen Plasma (FFP) and Thawed Plasma Description One unit of FFP or thawed plasma is the plasma taken from a unit of whole blood. FFP is frozen within eight hours of collection.
Bitchin Bread Battle Day 15: Outback Copycat Bread
Behold. This is the bread of deception. That dark brown color implies whole grains and exotic flours full of bowel bulking healthy goodness. I’m here to tell you it’s all a lie. This fluffy bread is freaking delicious because it’s full of chocolate and honey and butter.
About