• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Port Number while starting the server

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Replace the word "snake" with "danger noodle" in all tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic