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