List of usage examples for io.netty.channel.socket.nio NioDatagramChannel joinGroup
@Override
public ChannelFuture joinGroup(InetSocketAddress multicastAddress, NetworkInterface networkInterface)
From source file:com.barchart.netty.server.stream.MulticastTransceiver.java
License:BSD License
/** * Join the multicast group address using the network interface associated * with the given address./*w w w . ja va 2 s . c om*/ */ @Override public ChannelFuture listen(final SocketAddress address) { if (pipelineInit == null) { throw new IllegalStateException("No pipeline initializer has been provided, server would do nothing"); } // Kinda hacky, need to override bootstrap params based on passed // address final ChannelFuture future = bootstrap() // .option(ChannelOption.IP_MULTICAST_IF, bindInterface((InetSocketAddress) address)) // .localAddress(multicast.getPort()) // .remoteAddress(multicast) // .bind(); future.addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(final ChannelFuture future) throws Exception { if (future.isSuccess()) { final NioDatagramChannel channel = (NioDatagramChannel) future.channel(); channel.joinGroup(multicast, channel.config().getOption(ChannelOption.IP_MULTICAST_IF)); } } }); serverChannels.add(future.channel()); return future; }
From source file:org.codice.alliance.video.stream.mpegts.UdpStreamMonitor.java
License:Open Source License
private void runMulticastServer(Bootstrap bootstrap, NetworkInterface networkInterface, InetAddress inetAddress) { bootstrap.group(eventLoopGroup).channelFactory(() -> new NioDatagramChannel(InternetProtocolFamily.IPv4)) .handler(new Pipeline(udpStreamProcessor)).localAddress(inetAddress, monitoredPort) .option(ChannelOption.IP_MULTICAST_IF, networkInterface).option(ChannelOption.SO_REUSEADDR, true); try {/*from w w w. j av a2s.c o m*/ channelFuture = bootstrap.bind(monitoredPort).sync(); NioDatagramChannel ch = (NioDatagramChannel) channelFuture.channel(); ch.joinGroup(new InetSocketAddress(monitoredAddress, monitoredPort), networkInterface).sync(); } catch (InterruptedException e) { LOGGER.debug("interrupted while waiting for shutdown", e); } }