I am building a client / server with Netty 4.0. The server is listening properly on localhost:8083 and I can telnet on it, it triggers server breakpoints properly. But when I try to connect with that piece of code :
_bootstrap = new Bootstrap();
_bootstrap.group(locGroup)
.channel(NioServerSocketChannel.class)
.handler(new ClientInit(this, _sslContext, _logger));
_bootstrap.remoteAddress("127.0.0.1", 8083);
ChannelFuture locChannelFuture = _bootstrap.connect();
_channel = locChannelFuture.sync().channel();
It throws an exception at sync() : java.nio.channels.ClosedChannelException. As said before, when I telnet 127.0.0.1 8083 (or connect in code with a Socket), it does work. Any idea ? Thank you.
I fixed it. The problem was simply that I gave NioServerSocketChannel as the default channel class to the bootstrap constructor. Building a client, I put NioSocketChannel instead, and it's working fine.
So, here is the correct one :
_bootstrap.group(locGroup)
.channel(NioSocketChannel.class)
.handler(new ClientInit(this, _sslContext, _logger));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.