Example usage for java.net MulticastSocket getLoopbackMode

List of usage examples for java.net MulticastSocket getLoopbackMode

Introduction

In this page you can find the example usage for java.net MulticastSocket getLoopbackMode.

Prototype

public boolean getLoopbackMode() throws SocketException 

Source Link

Document

Get the setting for local loopback of multicast datagrams.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    int port = 0;
    byte ttl = (byte) 1;

    InetAddress ia = InetAddress.getByName("127.0.0.1");

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

    MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("java2s.com", 8080));
    ms.joinGroup(ia);//from   w  w w  .  j  a v a2s . c o m
    for (int i = 1; i < 10; i++) {
        ms.send(dp, ttl);
    }
    ms.leaveGroup(ia);

    System.out.println(ms.getLoopbackMode());

    ms.close();
}