List of usage examples for io.netty.channel ChannelOption IP_MULTICAST_LOOP_DISABLED
ChannelOption IP_MULTICAST_LOOP_DISABLED
To view the source code for io.netty.channel ChannelOption IP_MULTICAST_LOOP_DISABLED.
Click Source Link
From source file:com.mpush.client.gateway.GatewayUDPConnector.java
License:Apache License
@Override protected void initOptions(Bootstrap b) { super.initOptions(b); b.option(ChannelOption.IP_MULTICAST_LOOP_DISABLED, true); b.option(ChannelOption.IP_MULTICAST_TTL, 255); if (snd_buf.gateway_client > 0) b.option(ChannelOption.SO_SNDBUF, snd_buf.gateway_client); if (rcv_buf.gateway_client > 0) b.option(ChannelOption.SO_RCVBUF, rcv_buf.gateway_client); }
From source file:com.mpush.core.server.GatewayUDPConnector.java
License:Apache License
@Override protected void initOptions(Bootstrap b) { super.initOptions(b); b.option(ChannelOption.IP_MULTICAST_LOOP_DISABLED, true);//?????IP???IP_MULTICAST_LOOP???? b.option(ChannelOption.IP_MULTICAST_TTL, 255);//IP_MULTICAST_TTL?TTL0255 //b.option(ChannelOption.IP_MULTICAST_IF, null);//IP_MULTICAST_IF???????,?addr?IP?INADDR_ANY??? //b.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(32 * 1024, 1024 * 1024)); if (snd_buf.gateway_server > 0) b.option(ChannelOption.SO_SNDBUF, snd_buf.gateway_server); if (rcv_buf.gateway_server > 0) b.option(ChannelOption.SO_RCVBUF, rcv_buf.gateway_server); }
From source file:io.hekate.cluster.seed.multicast.MulticastSeedNodeProvider.java
License:Apache License
@Override public void startDiscovery(String cluster, InetSocketAddress address) throws HekateException { log.info("Starting seed nodes discovery [cluster={}, {}]", cluster, ToString.formatProperties(this)); SeedNode thisNode = new SeedNode(address, cluster); try {/*from w w w. j ava 2s . c o m*/ NetworkInterface nif = selectMulticastInterface(address); try { synchronized (mux) { if (isRegistered()) { throw new IllegalStateException( "Multicast seed node provider is already registered with another address " + "[existing=" + localNode + ']'); } ByteBuf discoveryMsg = prepareDiscovery(thisNode); ByteBuf seedNodeInfoBytes = prepareSeedNodeInfo(thisNode); localNode = thisNode; seedNodes = new HashSet<>(); eventLoop = new NioEventLoopGroup(1, new HekateThreadFactory("SeedNodeMulticast")); // Prepare common bootstrap options. Bootstrap bootstrap = new Bootstrap(); bootstrap.option(ChannelOption.SO_REUSEADDR, true); bootstrap.option(ChannelOption.IP_MULTICAST_TTL, ttl); bootstrap.option(ChannelOption.IP_MULTICAST_IF, nif); if (loopBackDisabled) { bootstrap.option(ChannelOption.IP_MULTICAST_LOOP_DISABLED, true); if (DEBUG) { log.debug("Setting {} option to true", ChannelOption.IP_MULTICAST_LOOP_DISABLED); } } bootstrap.group(eventLoop); bootstrap.channelFactory(() -> new NioDatagramChannel(ipVer)); // Create a sender channel (not joined to a multicast group). bootstrap.localAddress(0); bootstrap.handler(createSenderHandler(thisNode)); ChannelFuture senderBind = bootstrap.bind(); DatagramChannel localSender = (DatagramChannel) senderBind.channel(); sender = localSender; senderBind.get(); // Create a listener channel and join to a multicast group. bootstrap.localAddress(group.getPort()); bootstrap.handler(createListenerHandler(thisNode, seedNodeInfoBytes)); ChannelFuture listenerBind = bootstrap.bind(); listener = (DatagramChannel) listenerBind.channel(); listenerBind.get(); log.info("Joining to a multicast group " + "[address={}, port={}, interface={}, ttl={}]", AddressUtils.host(group), group.getPort(), nif.getName(), ttl); listener.joinGroup(group, nif).get(); // Create a periodic task for discovery messages sending. discoveryFuture = eventLoop.scheduleWithFixedDelay(() -> { if (DEBUG) { log.debug("Sending discovery message [from={}]", thisNode); } DatagramPacket discovery = new DatagramPacket(discoveryMsg.copy(), group); localSender.writeAndFlush(discovery); }, 0, interval, TimeUnit.MILLISECONDS); } } catch (ExecutionException e) { cleanup(); throw new HekateException( "Failed to start a multicast seed nodes discovery [node=" + thisNode + ']', e.getCause()); } log.info("Will wait for seed nodes [timeout={}(ms)]", waitTime); Thread.sleep(waitTime); } catch (InterruptedException e) { cleanup(); Thread.currentThread().interrupt(); throw new HekateException( "Thread was interrupted while awaiting for multicast discovery [node=" + thisNode + ']', e); } log.info("Done waiting for seed nodes."); }
From source file:picoview.collectd.CollectClient.java
License:Apache License
@Override public void initialize() throws RuntimeException { NetworkInterface nic;/*from w w w .j a v a 2s. co m*/ try { if (StringUtils.isBlank(nicName)) { nic = NetworkInterface.getByIndex(0); } else { nic = NetworkInterface.getByName(nicName); } } catch (SocketException exep) { throw new RuntimeException("unable to determine network interface to use", exep); } Bootstrap bs = new Bootstrap(); bs.option(ChannelOption.SO_BROADCAST, true); bs.option(ChannelOption.SO_REUSEADDR, true); bs.option(ChannelOption.IP_MULTICAST_LOOP_DISABLED, false); bs.option(ChannelOption.SO_RCVBUF, 2048); bs.option(ChannelOption.IP_MULTICAST_TTL, 255); bs.group(new NioEventLoopGroup()); bs.channelFactory(new ChannelFactory<Channel>() { public Channel newChannel() { return new NioDatagramChannel(InternetProtocolFamily.IPv4); } }); bs.handler(new ChannelInitializer<DatagramChannel>() { @Override public void initChannel(DatagramChannel channel) throws Exception { channel.pipeline().addLast(new CollectChannelHandler()); } }); if (StringUtils.isBlank(multicastHost)) { multicastHost = "239.192.74.66"; } if (multicastPort <= 0) { multicastPort = 25826; } try { DatagramChannel dch = (DatagramChannel) bs.bind(multicastPort).sync().channel(); ChannelFuture cf = dch.joinGroup(new InetSocketAddress(multicastHost, multicastPort), nic).sync(); if (!cf.isSuccess()) { throw new RuntimeException("unable to join multicast group"); } } catch (InterruptedException exep) { throw new RuntimeException("unable to setup network for collect client", exep); } }