Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.InetAddress; import java.net.MulticastSocket; import java.net.NetworkInterface; import java.util.Enumeration; public class JavaMulticastSocketsetInterfaceExample1 { public static void main(String[] args) throws IOException { MulticastSocket ms1 = new MulticastSocket(); NetworkInterface nif1 = NetworkInterface.getByIndex(1); Enumeration
enu = nif1.getInetAddresses(); InetAddress intadd = enu.nextElement(); ms1.setInterface(intadd); //setting the address of the network interface System.out.println("Interface : " + ms1.getInterface()); } }
Output