Netty在开发基于udp协议的代码中server段设置的参数broadcast有什么意义?
public static void initServer() {
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group)
.channel(NioDatagramChannel.class)
.option(ChannelOption.SO_BROADCAST, true)
.handler(new UdpServerHandler());
Channel channel = bootstrap.bind(AppConstants.SEARCH_PORT).sync().channel();
channel.closeFuture().await();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
group.shutdownGracefully();
}
}
设置SO_BROADCAST选项为0,只接受单播数据报 设置SO_BROADCASE选项为1,接受UDP广播