users@grizzly.java.net

Getting Local Port for Grizzly

From: Tahir Hashmi <tnhashmi_at_gmail.com>
Date: Wed, 13 Jun 2007 18:51:47 -0700

Hi!

While instantiating a SelectorThread, if we setPort(0), then the server
gets started on a system assigned port. However, when getPort() is
called on the server after successfully starting it, it returns 0. How
can I get the actual port on which the server is listening?

I tried the following but it didn't work:

SelectorThread server = new SelectorThread();
server.setPort(0);
server.start();

int port = server.getProcessorTask().getSocket().getLocalPort();

However, getSocket() returns null and an NPE results. Is there an
alternative way to do this?

Thanks

-- 
Tahir Hashmi
http://www.codemartial.org
I have seen The Source