Java - reduce Time-To-Live of UDP packet by sending it via MulticastSocket?

1.1k Views Asked by At

I need to send a few UDP packets that will not reach their destination (time to live value is very small). I am working in Java and I don't want to go through the hassle to writing and compiling native code for Windows, Ubuntu, and Mac just to set the TTL values of a few packets. I noticed that java.net.MulticastSocket has a "set time to live" option and that it extends DatagramSocket. Can I just send my short lived packets through a MulticastSocket with a small TTL value instead of through a DatagramSocket even though the short lived packets are not being multi-cast? Will that work?

2

There are 2 best solutions below

0
On BEST ANSWER

No. It does NOT work for all packets. MulticastSocket.setTimeToLive(0) does not affect normal UDP traffic sent via a MulticastSocket - it only affects packets sent as part of a multicast.

1
On

Yes, it will work for all packets.