Netty服务器无法连接
我编写了一个名为echo的tcp服务器示例,但它无法通过远程客户端连接。 这是我的密码:Netty服务器无法连接,netty,Netty,我编写了一个名为echo的tcp服务器示例,但它无法通过远程客户端连接。 这是我的密码: public class EchoServer { private int port = 8888; public void startServer() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGro
public class EchoServer {
private int port = 8888;
public void startServer() throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new EchoDecoder());
ch.pipeline().addLast(new EchoHandler());
}
}).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
ChannelFuture f = bootstrap.bind(port).sync();
System.out.println("bind completed.");
f.channel().closeFuture().sync();
System.out.println("channel closed.");
} finally {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
System.out.println("Closed");
}
}
public static void main(String[] args) throws Exception {
new EchoServer().startServer();
}
公共类EchoServer{
专用int端口=8888;
public void startServer()引发异常{
EventLoopGroup bossGroup=新的NioEventLoopGroup();
EventLoopGroup workerGroup=新的NioEventLoopGroup();
试一试{
ServerBootstrap bootstrap=newserverbootstrap();
bootstrap.group(bossGroup,workerGroup).channel(NioServerSocketChannel.class)
.handler(新的LoggingHandler(LogLevel.INFO))
.childHandler(新的通道初始值设定项(){
public void initChannel(SocketChannel ch)引发异常{
ch.pipeline().addLast(新的EchoDecoder());
ch.pipeline().addLast(新的EchoHandler());
}
}).option(ChannelOption.SO_BACKLOG,128)。childOption(ChannelOption.SO_KEEPALIVE,true);
ChannelFuture f=bootstrap.bind(port.sync();
System.out.println(“绑定完成”);
f、 通道().closeFuture().sync();
System.out.println(“通道关闭”);
}最后{
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
系统输出打印项次(“关闭”);
}
}
公共静态void main(字符串[]args)引发异常{
新的EchoServer().startServer();
}
}
等待您的答复,提前谢谢
运行环境:windows7 64位
netty版本:4.0.34也许可以查看windows防火墙?谢谢您的回答。我更新了java运行时环境,然后这个示例运行良好。