package upem.net.udp.multicast;

import java.io.IOException;
import java.net.*;
import java.nio.channels.DatagramChannel;
import java.nio.channels.MembershipKey;


public class MulticastConfig {

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

        NetworkInterface interf = NetworkInterface.getByName("eth0");
        InetAddress addressMulticast = InetAddress.getByName("239.252.0.100");
        int portMulticast = 7777;
        DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET);
        dc.setOption(StandardSocketOptions.SO_REUSEADDR, true);
        dc.bind(new InetSocketAddress(portMulticast));
        dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
        // Register socket to multicast address
        MembershipKey key = dc.join(addressMulticast, interf);


        // De-register socket form multicast address
        key.drop();
    }
}
