package com.xiaobao.gateway.protocol.udp; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioDatagramChannel; public class UDPEchoServer { static final int PORT = Integer.parseInt(System.getProperty("port", "8006")); public static void main(String[] args) { EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap bootstrap = new Bootstrap(); bootstrap .group(group) .channel(NioDatagramChannel.class) .option(ChannelOption.SO_BROADCAST, true) .handler(new ClientProxyHandler()); Channel channel = bootstrap.bind(PORT).sync().channel(); channel.closeFuture().sync(); } catch (Exception e) { System.out.println(e.getMessage()); } finally { group.shutdownGracefully(); } } }