Administrator
4 days ago cb78ad5f3aa9436cf32ae74f07dd1a5d18b8f046
src/main/java/cc/mrbird/febs/common/websocket/NettyWebSocketConfig.java
@@ -18,37 +18,37 @@
@Configuration
public class NettyWebSocketConfig {
    @Value("${netty.websocket.port:8090}")
    private int port;
    @Bean(name = "bossGroup", destroyMethod = "shutdownGracefully")
    public EventLoopGroup bossGroup() {
        return new NioEventLoopGroup(1);
    }
    @Bean(name = "workerGroup", destroyMethod = "shutdownGracefully")
    public EventLoopGroup workerGroup() {
        return new NioEventLoopGroup();
    }
    @Bean
    public ServerBootstrap serverBootstrap(EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 128)
                .childOption(ChannelOption.SO_KEEPALIVE, true)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new io.netty.channel.ChannelInitializer<io.netty.channel.socket.SocketChannel>() {
                    @Override
                    protected void initChannel(io.netty.channel.socket.SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new HttpServerCodec());
                        ch.pipeline().addLast(new ChunkedWriteHandler());
                        ch.pipeline().addLast(new HttpObjectAggregator(65536));
                        ch.pipeline().addLast(new WebSocketServerProtocolHandler("/ws"));
                        ch.pipeline().addLast(new cc.mrbird.febs.common.websocket.WebSocketServerHandler());
                    }
                });
        return bootstrap;
    }
//    @Value("${netty.websocket.port:9109}")
//    private int port;
//
//    @Bean(name = "bossGroup", destroyMethod = "shutdownGracefully")
//    public EventLoopGroup bossGroup() {
//        return new NioEventLoopGroup(1);
//    }
//
//    @Bean(name = "workerGroup", destroyMethod = "shutdownGracefully")
//    public EventLoopGroup workerGroup() {
//        return new NioEventLoopGroup();
//    }
//
//    @Bean
//    public ServerBootstrap serverBootstrap(EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
//        ServerBootstrap bootstrap = new ServerBootstrap();
//        bootstrap.group(bossGroup, workerGroup)
//                .channel(NioServerSocketChannel.class)
//                .option(ChannelOption.SO_BACKLOG, 128)
//                .childOption(ChannelOption.SO_KEEPALIVE, true)
//                .handler(new LoggingHandler(LogLevel.INFO))
//                .childHandler(new io.netty.channel.ChannelInitializer<io.netty.channel.socket.SocketChannel>() {
//                    @Override
//                    protected void initChannel(io.netty.channel.socket.SocketChannel ch) throws Exception {
//                        ch.pipeline().addLast(new HttpServerCodec());
//                        ch.pipeline().addLast(new ChunkedWriteHandler());
//                        ch.pipeline().addLast(new HttpObjectAggregator(65536));
//                        ch.pipeline().addLast(new WebSocketServerProtocolHandler("/ws"));
//                        ch.pipeline().addLast(new cc.mrbird.febs.common.websocket.WebSocketServerHandler());
//                    }
//                });
//        return bootstrap;
//    }
}