This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes regarding RMI architecture Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "regarding RMI architecture" Watch "regarding RMI architecture" New topic
Author

regarding RMI architecture

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

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: 475
    
    3
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
    
    1

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
    
    1

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: 475
    
    3
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
    
    1

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: 475
    
    3
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
 
Similar Threads
TCP/IP Communication
NX: RMI and Mutlithreading
URLyBird 1.3.1 How to identify clients?
TCP/IP Communication
TCP/IP Communication