#
whycq
2024-08-16 5bdad72f5d5077ca875dd03cfdaafb3d7aba93da
app/src/main/java/com/example/agvcontroller/socket/NettyServer.java
@@ -1,5 +1,8 @@
package com.example.agvcontroller.socket;
import com.example.agvcontroller.protocol.ProtocolDecoder;
import com.example.agvcontroller.protocol.ProtocolEncoder;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
@@ -32,9 +35,17 @@
                    .childHandler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        public void initChannel(SocketChannel ch) throws Exception {
                            ch.pipeline().addLast(new NettyServerHandler());
                            ch.pipeline().addLast(new ProtocolEncoder()).addLast(new ProtocolDecoder(4096)).addLast(new NettyServerHandler());
                        }
                    })
//                    .addLast(new NettyServerHandler())
//                    .childHandler(new ChannelInitializer<Channel>(){
//
//                        @Override
//                        protected void initChannel(Channel ch) throws Exception {
//                            ch.pipeline().addLast(new ProtocolEncoder());
//                        }
//                    })
                    .option(ChannelOption.SO_BACKLOG, 128)
                    .childOption(ChannelOption.SO_KEEPALIVE, true);