List of usage examples for io.netty.util NetUtil LOOPBACK_IF
NetworkInterface LOOPBACK_IF
To view the source code for io.netty.util NetUtil LOOPBACK_IF.
Click Source Link
From source file:com.barchart.netty.server.stream.MulticastTransceiver.java
License:BSD License
/** * Valid interface or loop back interface for error. *//*from ww w . java2 s . c o m*/ protected NetworkInterface bindInterface(final InetSocketAddress local) { try { final InetAddress address = local.getAddress(); final NetworkInterface iface = NetworkInterface.getByInetAddress(address); if (iface == null) { throw new IllegalArgumentException("address is not assigned to any iterface : " + address); } return iface; } catch (final Throwable e) { return NetUtil.LOOPBACK_IF; } }
From source file:com.heliosapm.shorthand.caster.broadcast.BroadcastListener.java
License:Open Source License
/** * Starts a listener on the passed socket address * @param isa The socket address to listen on * @param nic The network interface to listen on *///from w w w. j a v a 2 s . c o m public void startListener(InetSocketAddress isa, NetworkInterface nic) { Channel channel = null; if (isa.getAddress().isMulticastAddress()) { channel = bootstrap.group(group).channel(NioDatagramChannel.class) // .option(ChannelOption.SO_BROADCAST, true) .option(ChannelOption.IP_MULTICAST_ADDR, isa.getAddress()) .option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.IP_MULTICAST_IF, NetUtil.LOOPBACK_IF) .handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); pipeline.addLast(new LoggingHandler(BroadcastListener.class, LogLevel.DEBUG)); pipeline.addLast(router); } }).localAddress(isa).bind(isa.getPort()).syncUninterruptibly().channel(); ((NioDatagramChannel) channel).joinGroup(isa, NetUtil.LOOPBACK_IF).syncUninterruptibly(); //.bind(isa.getPort()).syncUninterruptibly().channel(); log("Bound to Multicast [%s]", isa); } else { channel = bootstrap.group(group).channel(NioDatagramChannel.class) .option(ChannelOption.SO_BROADCAST, true).handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel channel) throws Exception { ChannelPipeline pipeline = channel.pipeline(); pipeline.addLast(new LoggingHandler(BroadcastListener.class, LogLevel.DEBUG)); pipeline.addLast(router); } }).localAddress(isa).bind(isa).syncUninterruptibly().channel(); log("Bound to Broadcast UDP [%s]", isa); } boundChannels.add(channel); //.bind().syncUninterruptibly().channel(); boundChannels.add(channel); log("Started Broadcast Listener on [%s]", isa); }
From source file:reactor.ipc.netty.udp.UdpServerTests.java
License:Open Source License
private NetworkInterface findMulticastEnabledIPv4Interface() throws SocketException { if (isMulticastEnabledIPv4Interface(NetUtil.LOOPBACK_IF)) { return NetUtil.LOOPBACK_IF; }/*from w ww . ja v a 2 s. c o m*/ for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); ifaces .hasMoreElements();) { NetworkInterface iface = ifaces.nextElement(); if (isMulticastEnabledIPv4Interface(iface)) { return iface; } } throw new UnsupportedOperationException( "This test requires a multicast enabled IPv4 network interface, but " + "none" + " " + "were found"); }