Here is a nice program for getting the time
from a socket....For sw409 class....
import java.io.*;
import java.net.*;
public class NetUtil {
public static String getTime() {
return getTime("www.docjava.com");
}
public static String getTime(String host) {
String time = null;
Socket socket;
try {
socket = new Socket(host, 13);
BufferedReader in = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
time = in.readLine();
}
catch (UnknownHostException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return time;
}
public static void main(String[] args){
System.out.println(getTime("www.docjava.com"));
}
}
|