-1

I'm porting some old code, and getting this deprecation notice. What should I be upgrading this to?

warning: [deprecation] send(java.net.DatagramPacket,byte) in java.net.MulticastSocket has been deprecated
        socket.send(packet,(byte)ttl);

This is the code in question:

packet = new DatagramPacket(msg, msg.length, address, port);
socket.send(packet,(byte)ttl);

update:

If you are having problems with setting TTL (i.e. when you look at the packets, the TTL is always 1), then updating this code will not help (although it does make the deprecation warning go away). It's likely that you've encountered the Java runtime bug discussed here:

Java Multicast Time To Live is always 0

Community
  • 1
  • 1
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
  • Did you consider reading the Javadoc? – user207421 Sep 05 '13 at 22:13
  • 1
    @EJP, I did not. I've only ever written 12 lines of java code in my life, two of which appear above. They've worked perfectly since I first wrote them in 2008. Now we've apparently had a java version bump on our new system which was giving me this warning. One of the beauties of Stack Overflow is that a very casual user of a particular system can get help from an expert such as caskey, and that help can stick around for others. If I were to become a serious Java programmer I would spend time on the docs, but for now I'm just appreciatively relying on the help of others. – Mark Harrison Sep 05 '13 at 22:49
  • You're doing this wrong. You should *start* by reading the documentation concerned, *then* if you're still stuck try the internet. In this case you mould have got your answer immediately. That's why I suggested it. – user207421 Oct 07 '13 at 22:25
  • @EJP, point taken. It turns out that for me fixing the deprecated form didn't fix my problem, as there's a java runtime bug that manifests itself on boxes running dual ipv4/ipv6 stacks. Thanks! – Mark Harrison Oct 07 '13 at 23:11

1 Answers1

2

The javadocs tell you exactly what to do in the deprecation statement http://docs.oracle.com/javase/6/docs/api/java/net/MulticastSocket.html#send(java.net.DatagramPacket,%20byte)

// Deprecated. Use the following code or its equivalent instead:
int ttl = mcastSocket.getTimeToLive();
mcastSocket.setTimeToLive(newttl);
mcastSocket.send(p);
mcastSocket.setTimeToLive(ttl);
caskey
  • 12,305
  • 2
  • 26
  • 27