I will explain my query in the form of an example. I have my server(say server A),I need to connect to another server(say server B) so that I can have its time and set it on mine.Once set,the people using my server are suppose to get the new time(i.e the time from server B).Could anyone provide me with help.
The code I am posting here just gets the server time and prints it on the client machine but does not set the server time to the client machine.please provide help or links.
Client side code
class clienttime
{
public static void main(String args[]) throws Exception
{
//InetAddress locIP = InetAddress.getByName("192.168.1.55");
InetAddress locIP = InetAddress.getByName("127.0.0.1");
Socket soc= new Socket(locIP,123);
BufferedReader in=new BufferedReader(new InputStreamReader(soc.getInputStream()));
System.out.println(in.readLine());
}
}
Server side code
class servertime
{
public static void main(String args[]) throws Exception
{
InetAddress locIP = InetAddress.getByName("127.0.0.1");
ServerSocket s= new ServerSocket(7681, 0, locIP);
//ServerSocket s=new ServerSocket(5217);
while(true)
{
System.out.println("Waiting For Connection ...");
Socket soc=s.accept();
DataOutputStream out=new DataOutputStream(soc.getOutputStream());
String x = new Date().toString();
out.writeBytes("Server Date " + (new Date()).toString() + "\n");
out.close();
soc.close();
}
}