/**
*@description 监听指定端口
*@time 创建时间:2017年7月21日下午3:50:26
*@param port
*@throws InterruptedException
*@author dzn
*/
public void bind(int port) throws InterruptedException{
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workGroup = new NioEventLoopGroup();
try{
ServerBootstrap server = new ServerBootstrap();
server.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.childHandler(new ChildChannelHandler());
ChannelFuture cf = server.bind(port).sync();
System.out.println("服务器已启动, 监控端口号为 : " + port);
cf.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
RightTimeServer.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:netty_op
作者:
评论列表
文章目录