Getting Local Port for Grizzly

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting Local Port for Grizzly

Tahir Hashmi-2
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

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Getting Local Port for Grizzly

Oleksiy Stashok
Hello Tahir,

good catch :)
I've added this possibility with last commit.
please use:
server.getPortLowLevel();

WBR,
Alexey.


Tahir Hashmi wrote:

> 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
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]