getNetworkInterface(): This method is available in the java.net.MulticastSocket class of Java.
Syntax:
NetworkInterface java.net.MulticastSocket.getNetworkInterface() throws SocketException
This method gets the multicast network interface set.
Parameters: NA
Returns: The multicast NetworkInterface is currently set. A placeholder NetworkInterface is returned when there is no interface set; it has a single InetAddress to represent any local address.
Throws:
1. SocketException - if there is an error in the underlying protocol, such as a TCP error.
Approach
Java
package com.MulticastSocket;import java.io.IOException;import java.net.MulticastSocket;public class MulticastSocketgetNetworkInterface {public static void main(String[] args) throws IOException {MulticastSocket multicastSocket = new MulticastSocket();System.out.println(multicastSocket.getNetworkInterface());}}
Output:
name:0.0.0.0
Some other methods of MulticastSocket class
MulticastSocket(): This method constructs a multicast socket and binds it to any available port on the local host machine.
MulticastSocket(int): This method constructs a multicast socket and binds it to the specified port on the local host machine.
MulticastSocket(SocketAddress): This method creates a multicast socket, bound to the specified local socket address.
getNetworkInterface(): This method gets the multicast network interface set.
getTimeToLive(): This method gets the default time-to-live for multicast packets sent out on the socket.
joinGroup(SocketAddress, NetworkInterface): This method joins the specified multicast group at the specified interface.
leaveGroup(SocketAddress, NetworkInterface): This method leaves a multicast group on a specified local interface.
setNetworkInterface(NetworkInterface): This method specifies the network interface for outgoing multicast datagrams sent on this socket.
setTimeToLive(int): This method sets the default time-to-live for multicast packets sent out to this MulticastSocket in order to control the scope of the multicast.
No comments:
Post a Comment