public static void setInterface (MulticastSocket multicastSocket, boolean preferIpv6) throws IOException{ boolean interfaceSet = false; Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface i = (NetworkInterface) interfaces.nextElement(); Enumeration addresses = i.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = (InetAddress) addresses.nextElement(); if (preferIpv6 && address instanceof Inet6Address) { multicastSocket.setInterface(address); interfaceSet = true; break; } else if (!preferIpv6 && address instanceof Inet4Address) { multicastSocket.setInterface(address); interfaceSet = true; break; } } if (interfaceSet) { break; } } }
public static void setInterface (MulticastSocket multicastSocket, boolean preferIpv6) throws IOException{ boolean interfaceSet = false; Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface i = (NetworkInterface) interfaces.nextElement(); Enumeration addresses = i.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = (InetAddress) addresses.nextElement(); if (preferIpv6 && address instanceof Inet6Address) { multicastSocket.setInterface(address); interfaceSet = true; break; } else if (!preferIpv6 && address instanceof Inet4Address) { multicastSocket.setInterface(address); interfaceSet = true; break; } } if (interfaceSet) { break; } } }
@Override public DatagramChannelConfig setInterface(InetAddress interfaceAddress) { if (javaSocket instanceof MulticastSocket) { try { ((MulticastSocket) javaSocket).setInterface(interfaceAddress); } catch (SocketException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } return this; }
@Override public DatagramChannelConfig setInterface(InetAddress interfaceAddress) { if (javaSocket instanceof MulticastSocket) { try { ((MulticastSocket) javaSocket).setInterface(interfaceAddress); } catch (SocketException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } return this; }
protected void setInterface(InetAddress intf, MulticastSocket s) { try { if(s != null && intf != null) s.setInterface(intf); } catch(Throwable ex) { log.error("failed setting interface to %s: %s", intf, ex); } }
@Override public DatagramChannelConfig setInterface(InetAddress interfaceAddress) { if (javaSocket instanceof MulticastSocket) { try { ((MulticastSocket) javaSocket).setInterface(interfaceAddress); } catch (SocketException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } return this; }
public void setInterface(InetAddress interfaceAddress) { if (socket instanceof MulticastSocket) { try { ((MulticastSocket) socket).setInterface(interfaceAddress); } catch (SocketException e) { throw new ChannelException(e); } } else { throw new UnsupportedOperationException(); } }
MessageHandler(InetAddress bind_interface) throws Exception { mcast_sock = new MulticastSocket(mcast_port); mcast_sock.setInterface(bind_interface); mcast_sock.setTimeToLive(ttl); mcast_sock.joinGroup(mcast_addr); sock = new DatagramSocket(0, bind_interface); local_addr = sock.getLocalAddress(); local_port = sock.getLocalPort(); }
Receiver(InetAddress mcast_addr, InetAddress bind_interface, int port) throws Exception { sock=new MulticastSocket(port); if(bind_interface != null) sock.setInterface(bind_interface); sock.joinGroup(mcast_addr); System.out.println("Socket=" + sock.getLocalAddress() + ':' + sock.getLocalPort() + ", bind interface=" + sock.getInterface()); }
protected void sendRequest(InetAddress addr, InetAddress bind_addr, int port, int ttl, List<String> query, String passcode) throws Exception { if(mcast_sock == null) { mcast_sock=new MulticastSocket(); mcast_sock.setTimeToLive(ttl); if(bind_addr != null) mcast_sock.setInterface(bind_addr); } StringBuilder request=new StringBuilder(); byte[] authenticationDigest = null; if(passcode != null){ long t1 = (new Date()).getTime(); double q1 = Math.random(); authenticationDigest = Util.createAuthenticationDigest(passcode, t1, q1); } for(int i=0; i < query.size(); i++) { request.append(query.get(i)).append(" "); } byte[] queryPayload = request.toString().getBytes(); byte[] payload = queryPayload; if (authenticationDigest != null) { payload = new byte[authenticationDigest.length + queryPayload.length]; System.arraycopy(authenticationDigest, 0, payload, 0, authenticationDigest.length); System.arraycopy(queryPayload, 0, payload, authenticationDigest.length, queryPayload.length); } DatagramPacket probe=new DatagramPacket(payload, 0, payload.length, addr, port); mcast_sock.send(probe); // System.out.printf("-- sending probe request to %s:%d\n", addr, port); }
@Override public void openClient() throws Exception { // HORNETQ-874 if (checkForLinux() || checkForSolaris() || checkForHp()) { try { receivingSocket = new MulticastSocket(new InetSocketAddress(groupAddress, groupPort)); } catch (IOException e) { ActiveMQClientLogger.LOGGER.ioDiscoveryError(groupAddress.getHostAddress(), groupAddress instanceof Inet4Address ? "IPv4" : "IPv6"); receivingSocket = new MulticastSocket(groupPort); } } else { receivingSocket = new MulticastSocket(groupPort); } if (localAddress != null) { receivingSocket.setInterface(localAddress); } receivingSocket.joinGroup(groupAddress); receivingSocket.setSoTimeout(SOCKET_TIMEOUT); open = true; }
/** * Creates multicast socket and joins multicast group. * * @throws IOException If fails to create socket or join multicast group. * @return Multicast socket. */ private MulticastSocket createSocket() throws IOException { MulticastSocket sock = new MulticastSocket(mcastPort); sock.setLoopbackMode(false); // Use 'false' to enable support for more than one node on the same machine. if (sockItf != null) sock.setInterface(sockItf); if (sock.getLoopbackMode()) U.warn(log, "Loopback mode is disabled which prevents nodes on the same machine from discovering " + "each other."); sock.joinGroup(mcastGrp); if (ttl != -1) sock.setTimeToLive(ttl); return sock; }
sock.setInterface(bind_addr); sock.joinGroup(join_addr, null);
sock=new MulticastSocket(port); sock.setTimeToLive(ttl); sock.setInterface(v.get(i)); sockets[i]=sock; ack_receiver=new AckReceiver(sock);
mcast.setInterface(InetAddress.getByName(mcInterface));
socket = new MulticastSocket(); InetAddress localHost = SocketCreator.getLocalHost(); socket.setInterface(localHost); socket.setSoTimeout(Integer.getInteger("AvailablePort.timeout", 2000).intValue()); socket.setReuseAddress(true);
mcast_sock.setInterface(bind_addr); mcast_sock.joinGroup(mcast_addr);
sock.setInterface(sockItf);
/** * Start. * * @throws IOException */ final void init() throws IOException { socket = new MulticastSocket(groupMulticastPort.intValue()); if (hostAddress != null) { socket.setInterface(hostAddress); } socket.joinGroup(groupMulticastAddress); receiverThread = new MulticastReceiverThread(); receiverThread.start(); processingThreadPool = Executors.newCachedThreadPool(new NamedThreadFactory("Multicast keep-alive Heartbeat Receiver")); }
@Override public synchronized DatagramSocket getSocket() { if (getTheSocket() == null) { try { int port = getPort(); MulticastSocket socket = port == 0 ? new MulticastSocket() : new MulticastSocket(port); String localAddress = this.getLocalAddress(); if (localAddress != null) { InetAddress whichNic = InetAddress.getByName(localAddress); socket.setInterface(whichNic); } setSocketAttributes(socket); socket.joinGroup(InetAddress.getByName(this.group)); setSocket(socket); } catch (IOException e) { throw new MessagingException("failed to create DatagramSocket", e); } } return super.getSocket(); }