1
我想弄清楚如何獲得指向我的服務器引導產生的通道的指針。這個想法是我可能以後會做類似在Netty 4中如何獲得從ServerBootStrap子通道的指針
childChannel.write(x);
這是我目前擁有的代碼。
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() { @Override
public void initChannel(SocketChannel ch) throws Exception {
//ch.pipeline().addLast(new TimeEncoder(),new DiscardServerHandler());
ch.pipeline().addLast(
new ObjectEncoder(),
new ObjectDecoder(ClassResolvers.cacheDisabled(null)),
new ObjectEchoServerHandler());
}
});
ChannelFuture f = b.bind(port).sync();
//f.channel() returns the NioServerSocketChannel ... not the child
//@TODO need child channel...*********
謝謝!
謝謝!按需要工作 – M1LKYW4Y