Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Random Port Numbers ?

 
Ray Dawson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the master assignment, the client connects to the server through rmi.
The server runs on a particular port & the client gets the registry for that port & connects to it.

So I would like to get an advise from you guys that shall I randomly generate 4-digit port numbers which the server will use to create its rmiregistry ?
Like say if I use a fixed port for the server & that port is somehow blocked on the server machine then the ppl will have a hardtime fixing it, rather I'm generating a port no. which will get generated iff that port no. is not under use.
 
Carlos Morillo
Ranch Hand
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you do really need to think simple.

Typically Server Ports of a well known published service are kind of known and fixed.

If I remember correctly there is a well known default port for the RMI registry.

Why don't you just used that as the default?

You can give the freedom to the person starting the RMI server to specify an alternate port number.

Obviously you will need to handle the exception if the port number is already been used.

HTH,

Carlos.
 
Ray Dawson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.

Now I have kept the default RMI port (i.e 1099) as the default port no. it will listen to. Now if the port is already taken / blocked its exception will thrown & caught in which we will change the port no. to a free local port while notifying the user.
 
Carlos Morillo
Ranch Hand
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think my approach was just to throw an Exception if the port it's already been used.

I had a textfield in the GUI to start my RMI server with the default port number giving the option to the user to change it.


HTH,


Carlos.
 
Ray Dawson
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Roel De Nijs
Sheriff
Posts: 10386
132
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carlos Morillo wrote:I had a textfield in the GUI to start my RMI server with the default port number giving the option to the user to change it.

Exactly what I did. And when the user entered a port number which was already in use, the server was not starting and an error was shown to the user.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic