Java Code Examples for java.net.MulticastSocket#setLoopbackMode()

The following examples show how to use java.net.MulticastSocket#setLoopbackMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TcpDiscoveryMulticastIpFinder.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: MulticastDiscoveryAgent.java    From tomee with Apache License 2.0 6 votes vote down vote up
Multicast(final Tracker tracker) throws IOException {
    this.tracker = tracker;

    multicast = new MulticastSocket(port);
    multicast.setLoopbackMode(loopbackMode);
    multicast.setTimeToLive(timeToLive);
    multicast.joinGroup(address.getAddress());
    multicast.setSoTimeout((int) heartRate);

    listenerThread = new Thread(new Listener());
    listenerThread.setName("MulticastDiscovery: Listener");
    listenerThread.setDaemon(true);
    listenerThread.start();

    final Broadcaster broadcaster = new Broadcaster();

    timer = new Timer("MulticastDiscovery: Broadcaster", true);
    timer.scheduleAtFixedRate(broadcaster, 0, heartRate);

}
 
Example 3
Source File: NetUtils.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param multicastSocket
 * @param multicastAddress
 */
public static void joinMulticastGroup(MulticastSocket multicastSocket, InetAddress multicastAddress)
    throws IOException {
    setInterface(multicastSocket, multicastAddress instanceof Inet6Address);
    multicastSocket.setLoopbackMode(false);
    multicastSocket.joinGroup(multicastAddress);
}