Java MulticastSocket .setLoopbackMode (boolean disable)

Syntax

MulticastSocket.setLoopbackMode(boolean disable) has the following syntax.

public void setLoopbackMode(boolean disable)   throws SocketException

Example

In the following code shows how to use MulticastSocket.setLoopbackMode(boolean disable) method.


import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
//www  .  ja  va 2  s. c om
public class Main {
  public static void main(String[] args) throws Exception {
    int port = 0;
    byte ttl = (byte) 1;

    byte[] data = "Here's some multicast data\r\n".getBytes();
    DatagramPacket dp = new DatagramPacket(data, data.length, InetAddress.getByName("google.com"), port);

    MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("google.com", 8080));
    ms.joinGroup(InetSocketAddress.createUnresolved("127.0.0.1",8080),NetworkInterface.getByIndex(0));
    for (int i = 1; i < 10; i++) {
      ms.send(dp, ttl);
    }
    ms.setLoopbackMode(true);

    
    ms.close();
  }

}




















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder