News:

So the widespread use of emojis these days kinda makes forum smileys pointless, yeah?

Main Menu

[JAVA] Issue replying to Datagrams

Started by Lance, June 22, 2010, 06:49:10 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Lance

Some machines on my network are sending datagrams to me and I am trying to reply to them, but I am not sure how to code a datagram listener. The code below works (well, it receives the datagrams), but when I try to get the InetAddress it originated from, it is either null or my own InetAddress (I suppose it varies by what I try, but I always get one of those two results). How can I get the correct InetAddress to reply with another datagram?


setSocket(new DatagramSocket(1234)); // Just a setter for a DatagramSocket instance.

...

byte[] raw = new byte[256];
DatagramPacket datagram = new DatagramPacket(raw, raw.length);
getSocket() // Just a getter for a DatagramSocket instance.
          .receive(datagram);

...

datagram.getInetAddress(); // Either null or my InetAddress


Thanks :)
Quote from: Joe
[23:55:31] [william@enterprise ~/Documents/Programming/javaop2]$ svn commit -m 'Tried to fix StayConnected. Again.'
Committed revision 63.
StayConnected strikes back!