I'm trying to write an HTTP client, and I need to get the time from an NTP server I found here: https://tf.nist.gov/tf-cgi/servers.cgi
This is my Java code:
String getTime(){
String time = "";
try{
Socket timeSocket = new Socket("time-a-g.nist.gov",37);
BufferedReader timeIn = new BufferedReader(new InputStreamReader(timeSocket.getInputStream()));
time = timeIn.readLine();
timeSocket.close();
timeIn.close();
}
catch(IOException e){
e.printStackTrace();
}
return time;
}
I'm not getting any errors, but the string I'm getting back is null, can anyone help?