Bookmark Topic Watch Topic
  • New Topic

RMI Server start problem with port other then default port

 
Billy Tsai
Ranch Hand
Posts: 1304
  • Mark post as helpful
  • send pies
  • Report post to moderator
HI
when I try to start my RMI network server with the mode flag server I have a small GUI for user to input the port and I use java.rmi.registry.LocateRegistry.createRegistry(port);
DBDatabaseImpl record = new DBDatabaseImpl();
Naming.rebind("DB", record);
in my networking codes to start the RMI registry, the port value is obtain from the textfield inputed but the user from the small GUI.
but if I specify other ports instead of the default 1099 port the server is unable to start and an exception is show as java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect
I can use port 1099 fine without any problem and have even tested with client connecting to it but with any other ports no matter what number is enter the above exception occurs, I have tried this on different computers ,offline from internet and online on the internet with internet ip and the same problems occurs but with 1099 there will be no problem at all,
anyone know what is wrong and why is this happening?
please help
 
SrinivasMA Srini
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
Even I faced this problem. The reason is windows has one default file, That stores the host name etc. If that file contains localhost, by default it connects to localhost only. even though you type some junk value like this:
//right way
java <fileName> localhost 1099 db.db
//This also connects to localhost
java <fileName> wwwwwwwww 1099 db.db
The reason is winodws host file specifies this is the server name.
Also it is advisable to catch the following exception in your server code:
catch( IllegalArgumentException illegalArgumentException )
{
System.out.println( " Port number is out of range. It is recommended to use valid port number.");
System.exit( 0 );
}
This is the way I did in my assignment.
Cheers
Srinivas
SCJP,SCJD
 
Billy Tsai
Ranch Hand
Posts: 1304
  • Mark post as helpful
  • send pies
  • Report post to moderator
so is it possible to use other ports to start server programmatically?
and how?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Billy
It seems you have cross-posted this into this thread. Unfortunately I started answering you in that thread before seeing this one, and another person, has also added comments, so I won't repeat the answers here.
Regards, Andrew
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Since this is a cross post and the other post has your answer. I am going to close this thread.
Mark
 
    Bookmark Topic Watch Topic
  • New Topic