aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Random Port Numbers ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Random Port Numbers ?" Watch "Random Port Numbers ?" New topic
Author

Random Port Numbers ?

Ray Dawson
Ranch Hand

Joined: Sep 16, 2011
Posts: 75
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

Joined: Jun 06, 2009
Posts: 221

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.


SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Ray Dawson
Ranch Hand

Joined: Sep 16, 2011
Posts: 75
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

Joined: Jun 06, 2009
Posts: 221

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

Joined: Sep 16, 2011
Posts: 75
Thanks!
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5599
    
  15

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.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Random Port Numbers ?