This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding RMI architecture

 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I want to implement a project which will be on the basis of RMI.
I have one server and a couple of clients. When one client sends a screen to a server - server forwards it to other client.

I think that both client and server have to register their services in rmiregistry.
1). client invokes server's method to send a screen
2). server invokes client's method to forward a screen

Is it a good idea?

Thanks!
 
Karthik Shiraly
Bartender
Posts: 1195
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so all of the clients implement Client remote interface and server implements Server remote interface.
During client creation reference is passed to Server.
Is it good?
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written some code. Please, analyze that:

RemoteClient


Client


RemoteServer


Server


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.

Please give me an answer.
 
Karthik Shiraly
Bartender
Posts: 1195
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Cheers
Karthik
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it! Thanks.
 
Stephan King
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to barge in on this thread - haven't really used RMI - does RMI have a default port or how is that allocated in this particular code?
 
Karthik Shiraly
Bartender
Posts: 1195
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Stephan King
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic