java - What is the best approach to bind to different port / each port has different handler in Netty?, -


i want build application based on netty, need bind different ports @ same time, , each port needs have different handler logic. how in netty?

i searched online, , know can bind(host,port) multiple times, stills mean ports use same handler pipeline.

thank much

you create several serverbootstrap instances using single channelfactory. example:

    nioserversocketchannelfactory factory = new nioserversocketchannelfactory(             executors.newcachedthreadpool(), executors.newcachedthreadpool());      serverbootstrap bootstrap1 = new serverbootstrap(factory);     bootstrap1.setpipelinefactory(...);     bootstrap1.bind(new inetsocketaddress(port1));      serverbootstrap bootstrap2 = new serverbootstrap(factory);     bootstrap2.setpipelinefactory(...);     bootstrap2.bind(new inetsocketaddress(port2)); 

or, can dynamically modify pipeline. example in channelboundcallback:

@override public void channelbound(channelhandlercontext ctx, channelstateevent e) throws exception {     ctx.getpipeline().addlast("new", new simplechannelupstreamhandler() {         @override         public void messagereceived(channelhandlercontext ctx, messageevent e) throws exception {              ...         }     }); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -