Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Port Number while starting the server

 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers
The RMI server i developed takes 2 command line arguments:
1) port no where the registry/server will listen the request
2) location of database file (db.db)
I am not asking for IP addrees of the machine
where this server is installed.
is it correct ?
Now the problem is as i am taking the port number as parameter and create the registry at the same port using the method createRegistry()
When i try to do rebind(name,obj)
This method requires a url formatted name that includes the hostname and port no. But the problem is i dont have the ip address of machine
where server is being tried to run? If dont give a URL formatted name then though it will bind the object in the registry located at local host but it will also take the default port which i dont want.
I tried to obtain IP address using InetAddress but it does not work.
Pls Help
Amit
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could just make it automatically take the default port number.
For the client, it will need to get the ip address of the server, if it is to connect to the Remote server.
Mark
 
Charles Miller
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just specify this for the URL...
rmi://localhost:XXXX/RemoteDataImpl
where XXXX is the port number that you want to use
and RemoteDataImpl is changed to whatever you want to register as the RMI name.
 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Charles
Can i use InetAddress.getLocalHost().getHostAddress() to get the ip address of the
server machine.
Amit
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i use InetAddress.getLocalHost().getHostAddress() to get the ip address of the
server machine.

That will get you the IP address of the local machine. The client is the one that needs the IP address of the Server. So if you get the local machines IP address you won't get the server, of course unless it is running on the same machine.
Mark
 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark
Actually i was talking about using this at server only while binding the connection factory in registry.
Naming.rebind("rmi://"+InetAddress.getLocalHost().getHostAddress()":"+port +"/"+objConnectionFactory)
i am doing so as i am taking port no as command line argument from the user while starting the server.
Amit
 
Charles Miller
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the server when you are binding the object, you can specify 'localhost', you don't have to use the machine name or an IP.
When the client needs to make the remote connection, you will either need to specify the machine name (NOT localhost) or the IP of the server machine.
IE. when I start my server, I use 'localhost' in the URL string to bind the remote object.
When I start the client, I specify 192.168.1.210 as the server machine (since I use a local network).
 
Amit Kr Kumar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks charles
Yours is also correct but still i dont find any harm in using InetAddress.getLocalHost().getHostAddress()
Both are correct

What do u say ?
Amit
 
Charles Miller
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer the 'localhost' way since it avoids 2 method calls (thereby improving performance), though either way gets the job done.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Naming.rebind("rmi://"+InetAddress.getLocalHost().getHostAddress()":"+port +"/"+objConnectionFactory)

What are you guys talking about? My rebind looks as simple as this, and it works:
rebind("Database Service", remoteDataFactory);
Am I missing anything?
Eugene.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Eugene, yours is fine. Mine was that simple too, but there are some who want to give the user that starts things up more flexibility, even though you don't need it. But it is fine for them to have that flexibility, it is really just a preference.
Mark
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic