I want to randomly generate ports using TransporterServer. Currently I can wrap POJO's and beam them with a server with a known port number.
To get around this I am currently storing the last port used and incrementing by one, then creating a Locator, then passing it to one of the TransporterServer.create??? methods. The issue is that sooner or later I will clash on an already in use port.
OK, I can catch the exception and loop but is there a better way.
If I try and use a PORT of 0 for the port in the locator string, when passed to the a TranporterServer.create??? this should produce a server on a random port. Unfortunately I cannot find a way get the actual PORT it used and therefore cannot create a locator for the client.
Note the POJO's carry state so I need a server for each client.
Any suggestions welcome, thanks, Graeme
Hi Graeme,
org.jboss.remoting.transport.PortUtil.findFreePort() will return an available port. It also loops until it finds a free port, but it would be cheaper than creating a Connector each time around the loop.