@JFinal 你好
为要做的新项目做个技术调研,想使用JFinal 和 Netty ,把Netty 通信服务于JFinal 集成使用,但是在做试验时在afterJFinalStart()中启动Netty 的TCP的服务端,Netty 相关代码如下(官网示例):
public class NettyServerBootstrap { private int port; public NettyServerBootstrap(int port) { this.port = port; bind(); } private void bind() { EventLoopGroup boss = new NioEventLoopGroup(); EventLoopGroup worker = new NioEventLoopGroup(); try { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(boss, worker); bootstrap.channel(NioServerSocketChannel.class); bootstrap.option(ChannelOption.SO_BACKLOG, 1024); //连接数 bootstrap.option(ChannelOption.TCP_NODELAY, true); //不延迟,消息立即发送 bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true); //长连接 bootstrap.childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel socketChannel) throws Exception { ChannelPipeline p = socketChannel.pipeline(); p.addLast(new NettyServerHandler()); } }); ChannelFuture f = bootstrap.bind(port).sync(); if (f.isSuccess()) { System.out.println("启动Netty服务成功,端口号:" + this.port); } // 关闭连接 f.channel().closeFuture().sync(); } catch (Exception e) { System.out.println("启动Netty服务异常,异常信息:" + e.getMessage()); e.printStackTrace(); } finally { boss.shutdownGracefully(); worker.shutdownGracefully(); } } }
afterJFinalStart()中启动:
public void afterJFinalStart(){ NettyServerBootstrap server = new NettyServerBootstrap(8899); }
这样Netty 的TCP服务能够成功启动,但是jeety.start()不能启动,这个web不能访问。
还请大神指点!