java - NTP for TCP/IP(server-client) -


i have simple server...

public static void main(string[] args) throws exception{     serversocket server = new serversocket(2000);     socket sock = server.accept();     inputstream  in = sock.getinputstream();     outputstream out = sock.getoutputstream();     printwriter w = new printwriter(out);     scanner s = new scanner(in);     ... 

and simple client...

public static void main(string[] args) throws exception{     socket sock = new socket("localhost",2000);;     inputstream in= sock.getinputstream();     outputstream out = sock.getoutputstream();     printwriter w  = new printwriter(out);     scanner s = new scanner(in);     .... 

-how can connect more clients server? (i need 2 more) -also want send system time server clients , clients send time 10 times each plus fixed delay (0.5-1 sec) server must find average delays , send clients new time...

thank time...

system.currenttimemillis() provides system time

every socket returned server.accept() separate object , server can communicate independently each client through each socket object. however, since application time-sensitive, recommend using separate thread each client.

a simple server be:

serversocket serversock = new serversocket(2000);  while (true) {     socket fpsock = serversock.accept();     mythread t = new mythread(fpsock, this);     t.start(); } 

the processing need done in mythread run() method. "this" passed thread provide reference each thread can callback methods in main class. make sure make such methods synchronized.

you don't need send server's time client, send generic packet client expected echo back. use server's timestamp transactions avoid variation in client system time.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -