Originally posted by walid aly:
1-is there is any way the rmi server can know that a certain a client is connected and then know when it leaves.
Check out the java.rmi.server.Unreferenced interface. If your Remote object implements this interface, RMI will call the unreferenced() method when it finds that no more remote references to the object exist. In some ways, it's like a remote version of finalize(). Beware that an entry in the RMI registry is a remote reference---as long as the object is in the registry, unreferenced() will not be called.
If you need immediate notification, consider making clients call a close() method or similar.
2.a more simple question [...] y do we always make the class that implement a remote interface always throw remoteexecption in the implemented methods
We don't. The class
Is a perfectly valid implementation of the interface X you listed above.
The method in X needs to throw RemoteException because the RMI transport mechanism can throw it. So while your object will never throw RemoteException, the stub object that clients use can definitely throw RemoteException when there is some type of RMI problem (e.g. networking problems, or marshalling problems if your classes get out of sync).
- Peter