MulticastSocket GetInterface() Example
Returns An InetAddress representing the address of the network interface
MulticastSocketclass GetInterface() method example. This example shows you how to use GetInterface() method.This method Returns An InetAddress representing the address of the network interface
Here is the code:-
/*
* @Program that Retrieve the address of the network interface.
* GetInterface.java
* Author:-RoseIndia Team
* Date:-27-Jun-2008
*/
import java.net.*;
public class GetInterface {
public static void main(String[] args) throws Exception {
SocketAddress sa = new InetSocketAddress(8080);
MulticastSocket ms = new MulticastSocket(sa);
//Specify the network interface for outgoing multicast datagrams sent
ms.setInterface(InetAddress.getByName("localhost"));
//Retrieve the address of the network interface.
System.out.println("Address of the network interface is: "
+ms.getInterface());
}
} |
Output of the program:-
| Address of the network interface is: localhost/127.0.0.1 |
|