Java MulticastSocket setTimeToLive(int ttl) Method

setTimeToLive(int ttl) is the method of MulticastSocket class. This method is used to set the default time-to-live for the multicast packets which are sent out on the socket in order to control the scope of the multicasts. The range 0 <= ttl <= 255 or an IllegalArgumentException will be thrown.

Syntax

Parameter

ttl - it is the time-to-live

Throw

IOException - this exception occurs while getting the default time-to-live value.

Example 1

Test it Now

Output:

Time to Live : 20

Example 2

Test it Now

Output:

Time to Live : 40




Latest Courses