上饶市公安局wvp平台
zhongrj
2025-01-16 f1d079f9c0b3d384090477ca54e0548373d62b57
src/main/java/com/genersoft/iot/vmp/netty/server/UdpServer.java
@@ -1,12 +1,12 @@
package com.genersoft.iot.vmp.netty.server;
import com.genersoft.iot.vmp.netty.config.MyDecoder;
import com.genersoft.iot.vmp.netty.handle.UdpServerHandler;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;
import org.slf4j.Logger;
@@ -53,13 +53,16 @@
                            // TODO Auto-generated method stub
                            //创建一个执行Handler的容器
                            ChannelPipeline pipeline = ch.pipeline();
                            pipeline.addLast(new StringDecoder());
                            pipeline.addLast(new StringEncoder());
//                            pipeline.addLast(new StringDecoder());
                            pipeline.addLast("decoder",new MyDecoder());
//                            pipeline.addLast(new StringEncoder());
                            pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 4, 4, -8, 0));
                            //执行具体的自定义处理器
                            pipeline.addLast(group, "handler", new UdpServerHandler());
                        }
                    })//初始化处理器
                    //true / false 多播模式(UDP适用),可以向多个主机发送消息
                    .option(ChannelOption.SO_BROADCAST, true)
                    // 设置UDP读缓冲区为2M