• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do we need host,port,and db name when we use RMI ?

 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
According to my understanding,a server object registers itself with rmiregistry using a name. The client lookups the server object using the same name. This is what I found from several books and articles.Under this understanding:
1) What's the purpose for us to provide the host DNS, and port as command line arguments ?
Besides of using them to distinguish the local and remote mode, I can not see they are needed for remote communication or remote data access.
I know that they are absolutely necessary for Socket. But,I can not see the purpose for us to have them in RMI implementation. Please explain to me how we can use them for remote communication in RMI.
2) In which machine should we start the rmiregistry ? If the rmiregistry is started in server machine,how can client find the rmiregistry ? Vice or Versa for server ?
Thanks,
John Chien
 
lev grevnin
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey man,
As for "1)":
First of all, i hope when you say "provide the host DNS and port " you are referring to the client. So that's that.
Here is an example command line used to access remote objects from some client:
DataServer dataServer = (DataServer) Naming.lookup("rmi://" + arg[0] + ":" + arg[1] + "/DataServer"); where arg[0] stands for host (as an IP number or DNS name) and arg[1] for port (as an ordinary integer)
Clearly, you need to know the IP address and the port number. (actually you can skip the port numeber as in rmi://somehost/DataServer. in this case the client will try to connect to the server on the standard RMI port which is 1099)
as for "2)":
rmiregistry is started on the server machine:
>rmiregistry 3456
for example.
If skip port, the default port will be used and the client will have to try to connect to this default port (1099) to successfully locate the remote object DataServer.
So the client on the othere side of the connection tried to connect to the specified host name and port. this is why you need these two parameters.
hope i helped you a bit.
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lev:
Thank you for the response.
I re-look at the RMI book that I consulted.
I think you are right.
In the book, the client does the lookup using the host: rmi://host/dataserver and the server register using rmi://dataserver. Originally, I thought that is a typo. Now, I know that it is needed.
Thanks,
John Chien
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic