private synchronized DatagramChannel getChannel() throws IOException {
if (channel == null || !channel.isOpen()) {
if (shutdown.get()) {
throw new IllegalStateException("Channel has been shut down");
}
ProtocolFamily protocolFamily = InternetProtocolUtils.getProtocolFamily(group.getAddress().getAddress());
DatagramChannel _channel = selector.provider().openDatagramChannel(protocolFamily);
_channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
// bind to any-local before setting TTL
int port = group.getAddress().getPort();
if (protocolFamily == StandardProtocolFamily.INET) {
_channel.bind(new InetSocketAddress(Inet4Address.getByName("0.0.0.0"), port));
} else {
_channel.bind(new InetSocketAddress(Inet6Address.getByName("[::]"), port));
}
int timeToLive = group.getTimeToLive();
if (timeToLive != 1) {
_channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, timeToLive);
}
for (NetworkInterface iface : networkInterfaces) {
_channel.join(group.getAddress().getAddress(), iface);
}
_channel.configureBlocking(false);
channel = _channel;
}
return channel;
}
AnnounceGroupChannel.java 文件源码
java
阅读 19
收藏 0
点赞 0
评论 0
项目:bt
作者:
评论列表
文章目录