MulticastSocket SetTimeToLive() Example
Set the default time-to-live for multicast packets sent out on this MulticastSocket
MulticastSocketclass SetTimeToLive() method example. This example shows you how to use SetTimeToLive() method.This method Set the default time-to-live for multicast packets sent out on this MulticastSocket
Here is the code:-
/*
* @Program that Set the default time-to-live for multicast packets
* SetTimeToLive.java
* Author:-RoseIndia Team
* Date:-27-Jun-2008
*/
import java.net.*;
public class SetTimeToLive {
public static void main(String[] args) throws Exception {
SocketAddress sa = new InetSocketAddress(8080);
MulticastSocket ms = new MulticastSocket(sa);
//Get the default time-to-live for multicast packets
System.out.println("Default time-to-live is: "
+ms.getTimeToLive());
//Set the default time-to-live for multicast packets
ms.setTimeToLive(2);
System.out.println("Default time-to-live is: "
+ms.getTimeToLive());
}
} |
Output of the program:-
Default time-to-live is: 1
Default time-to-live is: 2 |
|