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