Can netty bind to multiple ports?

Frederic Bregier fredbregier at free.fr
Sat Sep 5 15:06:07 EDT 2009


Hi,

I think you can write:

     bootstrap.setPipelineFactory(new FastMarketDataPipelineFactory());
     ChannelGroup allChannels = new DefaultChannelGroup();

     for (SocketAddress port : fromFile) { // where fromFile could be a list
of InetSocketAddres(ports)
         Channel serverChannel = bootstrap.bind(port); // it will create a
new "father" channel for each port
         allChannels.add(serverChannel);
     }

and when you shutdown:

     // Close the serverChannel and then all accepted connections.
     allChannels.close().awaitUninterruptibly();
     b.releaseExternalResources();

This way you only have one bootstrap (it is made to be used as many times
you wanted) which produces several server channels listening on different
ports.

HTH,
Frederic


falconair wrote:
> 
> Given code like this:
> public static void main( String[] args )
>     {
>      ChannelFactory factory =
>      new NioServerSocketChannelFactory(
>      Executors.newCachedThreadPool(),
>      Executors.newCachedThreadPool());
> 
>      ConnectionlessBootstrap bootstrap = new
> ConnectionlessBootstrap(factory);
> 
>      bootstrap.setPipelineFactory(new FastMarketDataPipelineFactory());
> 
>      //I want to do this
>      //bootstrap.bind(getMultiplePortsFromFile());//<==============
>      //I don't want to do this
>      bootstrap.bind(getSinglePort());
>     }
> 
> I'd like to avoid writing one bootstrap for each port to avoid writing
> more
> code, avoid performance penalty (if any), etc.
> 
> On Sat, Sep 5, 2009 at 1:46 AM, Mike McGrady (via Nabble) <
> ml-user+56678-1543996500 at n2.nabble.com<ml-user%2B56678-1543996500 at n2.nabble.com>
>> wrote:
> 
>> I do not see what the problem is.  Certainly you can bind to any and
>> as many ports as you like.  How does your problem arise?
>>
>> Sent from my iPhone
>>
>> On Sep 4, 2009, at 7:38 PM, falconair <[hidden
>> email]<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=3584040&i=0>>
>> wrote:
>>
>> >
>> > I need to listen to stock market data, published as UDP on a number
>> > of ports.
>> > I need to parse these messages and publish them to their respective
>> > jms
>> > topics.
>> >
>> > How can I listen to multiple ports?   bind equivalent function can
>> > take a
>> > set of internet addresses, I didn't see anything like that for
>> > Netty.  Did I
>> > miss something?
>> >
>> > Thanks
>> > --
>> > View this message in context:
>> http://n2.nabble.com/Can-netty-bind-to-multiple-ports-tp3583597p3583597.html
>> > Sent from the Netty User Group mailing list archive at Nabble.com.
>> > _______________________________________________
>> > netty-users mailing list
>> > [hidden
>> email]<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=3584040&i=1>
>> > https://lists.jboss.org/mailman/listinfo/netty-users
>> _______________________________________________
>> netty-users mailing list
>> [hidden
>> email]<http://n2.nabble.com/user/SendEmail.jtp?type=node&node=3584040&i=2>
>> https://lists.jboss.org/mailman/listinfo/netty-users
>>
>>
>> ------------------------------
>>  View message @
>> http://n2.nabble.com/Can-netty-bind-to-multiple-ports-tp3583597p3584040.html
>> To unsubscribe from Can netty bind to multiple ports?, click here< (link
>> removed) >.
>>
>>
>>
> 
> 


-----
Hardware/Software Architect
-- 
View this message in context: http://n2.nabble.com/Can-netty-bind-to-multiple-ports-tp3583597p3586748.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list