I want to do time request on an socket client. According to this time.nist.gov is on port 13
Does time.google.com have a similar service so that I can connect a socket client to it. just like I can connect to time.nist.gov on port 13
I wanted to do something like this
import java.net.*;
import java.io.*;
/**
* This program is a socket client application that connects to a time server
* to get the current date time.
*
* @author www.codejava.net
*/
public class TimeClient {
public static void main(String[] args) {
String hostname = "time.google.com";
int port = 13;
try (Socket socket = new Socket(hostname, port)) {
InputStream input = socket.getInputStream();
InputStreamReader reader = new InputStreamReader(input);
int character;
StringBuilder data = new StringBuilder();
while ((character = reader.read()) != -1) {
data.append((char) character);
}
System.out.println(data);
} catch (UnknownHostException ex) {
System.out.println("Server not found: " + ex.getMessage());
} catch (IOException ex) {
System.out.println("I/O error: " + ex.getMessage());
}
}
}