This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Didn't understand why all the clients need to register in rmiregistry. Each client can implement a client interface (which should also be remote) and pass a reference to that while registering with server. Server uses the received reference to communicate with client.
Please, notice that I do not use ClientRemote interface - I do not register it in rmiregistry.
I just pass a client's reference to Server and then Server invokes methods on that object. I tried it on localmachine and it works.
What about distributed machines? Will that work? I do not think so.
Sorry, am seeing this only now since I didn't get an email alert.
Yes, it works even in distributed case - I know because I've them working. Why do you feel it won't work?
Registering with naming registry is simply to give a label to a java reference so that other objects can get it. In the above code, RemoteClient reference is given directly to server, so it is being used, but just not registered.
By default, RMI naming registry is reachable on port 1099. In this code, the line
does not specify a port, so it defaults to 1099.
But that's not the only port in picture. Once lookup is done, client and server setup a TCP connection over random ports, unless server specifies specific port on which it'll communicate. This code is not doing it, but it can be done in the RemoteServer constructor as: