I'm attempting to grab a timestamp off an nist.gov server using the code below.
InetAddress addr = InetAddress.getByName("129.6.15.30");
DatagramSocket s = new DatagramSocket();
System.out.println("Connected to: "+addr.getHostName());
byte[] buf = new byte[4];
DatagramPacket p = new DatagramPacket(buf, buf.length, addr, 37);
s.send(p);
System.out.println("message sent");
DatagramPacket dp = new DatagramPacket(buf, buf.length);
s.receive(dp);
String data = new String(dp.getData(), 0, dp.getLength());
System.out.println("Received: "+data);
When I run this on Eclipse, I get the following back in the console.
Connected to: time-c.nist.gov
message sent
Received: ÛÏÌ<
Good news is, I'm connecting to the correct server and getting back a packet. However, I just can't seem to turn that packet's data into a comprehensible representation of that data. What am I missing?