title: How to make an RMI server multi-client program without registerting clients
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>How does one achieve this without registering every client as a server?</p>
  
  <p>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: </p>
  
  <pre><code>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
  </code></pre>
  
  <p>On this class</p>
  
  <pre><code>public class GameClient extends Thread implements Remote, Client, ModelChangeListener&lt;Client&gt;{
      private static final long serialVersionUID = -394039736555035873L;
      protected Queue&lt;GameModelEvent&gt; queue = new ConcurrentLinkedQueue&lt;GameModelEvent&gt;(); 
  
  
      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;
              }
          }
  
      }
  ...
  </code></pre>
  
  <p>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.</p>
  
  <p>Any ideas on what is wrong?</p>