Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Server to client communication is a bit of a minefield in all remoting technologies, including RMI. This is probably why you are struggling to find much documentation on the subject. For a dummy program in a controlled environment the following approach will work and is the simplest way to go. Note that all error handling has been omitted.</p> <pre><code>import java.rmi.Remote; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; interface ClientRemote extends Remote { public void doSomething() throws RemoteException; } interface ServerRemote extends Remote { public void registerClient(ClientRemote client) throws RemoteException; } class Client implements ClientRemote { public Client() throws RemoteException { UnicastRemoteObject.exportObject(this, 0); } @Override public void doSomething() throws RemoteException { System.out.println("Server invoked doSomething()"); } } class Server implements ServerRemote { private volatile ClientRemote client; public Server() throws RemoteException { UnicastRemoteObject.exportObject(this, 0); } @Override public void registerClient(ClientRemote client) throws RemoteException { this.client = client; } public void doSomethingOnClient() throws RemoteException { client.doSomething(); } } </code></pre> <p>Usage: Create a Server object on the server, add it to your RMI registry and look it up on the client. </p> <p>There are other technologies that make client notifications easier, Java Message Service (JMS) is commonly used for this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload