| Author |
regarding RMI architecture
|
Lucas Smith
Ranch Hand
Joined: Apr 20, 2009
Posts: 804
|
|
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!
|
SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
|
 |
Karthik Shiraly
Ranch Hand
Joined: Apr 04, 2009
Posts: 366
|
|
|
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
Joined: Apr 20, 2009
Posts: 804
|
|
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
Joined: Apr 20, 2009
Posts: 804
|
|
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
Ranch Hand
Joined: Apr 04, 2009
Posts: 366
|
|
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
Joined: Apr 20, 2009
Posts: 804
|
|
|
Got it! Thanks.
|
 |
Stephan King
Greenhorn
Joined: Apr 11, 2010
Posts: 13
|
|
|
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
Ranch Hand
Joined: Apr 04, 2009
Posts: 366
|
|
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
Joined: Apr 11, 2010
Posts: 13
|
|
Thanks
|
 |
 |
|
|
subject: regarding RMI architecture
|
|
|