#
whycq
2024-08-17 20245e35da8a9d809b2de91f4ec29dd39127f9d5
app/src/main/java/com/example/agvcontroller/socket/NettyServer.java
@@ -1,5 +1,9 @@
package com.example.agvcontroller.socket;
import com.example.agvcontroller.protocol.MessageBodyHandler;
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 +36,20 @@
                    .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 MessageBodyHandler())
                                    .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);