How to find Channel request port

Trustin Lee tlee at redhat.com
Wed Mar 25 04:46:47 EDT 2009


Hi Richard,

On Mon, Mar 23, 2009 at 1:07 PM, Richard Jackson
<richard.jackson at gmail.com> wrote:
> This may be covered somewhere but I can't seem to be able to find what
> I'm looking for. So lets assume I have done something like this:
>
>        ServerBootstrap bootstrap = new ServerBootstrap(factory);
>        HttpServerPipelineFactory pipeline =
>                new HttpServerPipelineFactory(new HttpRequestHandler());
>          bootstrap.setPipelineFactory(pipeline);
>          // Configure our server code goes here....
>          ....
>          bootstrap.bind(8080);
>          bootstrap.bind(8081);
>          .... More stuff...
>
> As you can see I have bound two ports to the same server. So the
> question is how do I find out in my handler which port the request
> came in on? I do see that from the channel I can get a SocketAddress
> with Channel.getLocalAddress() but that still will not tell me which
> port the request came in on.

You can downcast SocketAddress to InetSocketAddress, then it will tell
you the port number. :)

HTH,

— Trustin Lee, http://gleamynode.net/




More information about the netty-users mailing list