简体   繁体   English

网路连线无法运作

[英]Netty Connection not working

I've the following source: https://hastebin.com/ovekebahij.java 我有以下来源: https : //hastebin.com/ovekebahij.java

bootstrap.group( eventLoopGroup )
                    .channel( serverSocketChannelClass )
                    .option( ChannelOption.SO_KEEPALIVE, true )
                    .handler( new ChannelInitializer<NioServerSocketChannel>() {
                        @Override
                        protected void initChannel( NioServerSocketChannel nioServerSocketChannel ) throws Exception {
                            callback.onSuccess( preparePipeline( nioServerSocketChannel ) );
                        }
                    });

I don't know why but my log says me, that the server is successfully started. 我不知道为什么,但是我的日志告诉我,服务器已成功启动。 Each time I try to connect a client, it says that it cannot connect... anyone an Idea? 每次我尝试连接客户端时,都会说它无法连接...任何人有想法吗?

Thanks for each contribution. 谢谢你的贡献。

Its because your server bootstrap method does not block and so close the socket after it was bound. 这是因为服务器引导程序方法不会阻塞,因此在绑定后关闭套接字。

You should change the code to be: 您应该将代码更改为:

Channel channel = bootstrap.bind(...).sync().channel();
...
channel.closeFuture().sync()

This will ensure the method will only return after the socket is closed. 这将确保仅在关闭套接字后才返回该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM