Sorry I was wrong again:
Here is what I think may be good :
boolean responseDesired = true;
if (m.getRemoteTime() != -1) {
m.getMessageClient().setTimeConversion(
System.currentTimeMillis() - m.getRemoteTime());
responseDesired = false;
}
if (m.isResponseDesired()) {
m.setRemoteTime(System.currentTimeMillis());
m.setLocalTime(m.getLocalTime());
m.setResponseDesired(responseDesired);
m.getMessageClient().sendMessage(m);
}
So you were right as usual, except you swapped the local/remote time fields, whereas not!an!exit got lost in a einsteinian physic time sync paradox.
How I see it:
client sends server a message to bring back time
server fullfills remotetime with its system time.
client receives it and try to make the difference:
Here is what I think is correct :
1) first we want to have a real clock difference: we have to add the return time roundtrip/2 to the servertime to have success clock adjust. realtime = system.gettime - (m.getservertime + roundtrip/2). <- like this we talk about the time at the same moment.now we have realtime difference.
2) we have to add roundtrip/2 to have relativetime difference.
so it becomes: relativetime = system.gettime - m.getservertime
Now when calling synchronizetimeandwait we have got real server time difference plus information transiting time that is the real remote time
The results I get:
calling synchronizetimeandwait on one pc gives quite results between 2 and 5ms
between two wifi pc I got more eratics results between 2 and 10 ms ( the system ping varies quite the same)
The only detail I see is that on a calculus time consideration, if the server or the client is slow for example, the roundtrip may be composed for example by 2/3 a direction 1/3 the other. In this case, we should modify a bit what is upperto substract the appropriate one way trip and add the other ...
Hope we are talking about the same thing and this is correct

Kine
package tests;
import java.net.InetSocketAddress;
import com.captiveimagination.jgn.JGN;
import com.captiveimagination.jgn.MessageServer;
import com.captiveimagination.jgn.TCPMessageServer;
public class DFTestTimeSynchronizationServer {
public static void main(String[] args) throws Exception {
System.out.println("here we go !!");
MessageServer server1 = new TCPMessageServer(new InetSocketAddress(
10000));
JGN.createThread(server1).start();
}
}
package tests;
import java.io.IOException;
import java.net.InetSocketAddress;
import com.captiveimagination.jgn.JGN;
import com.captiveimagination.jgn.MessageClient;
import com.captiveimagination.jgn.MessageServer;
import com.captiveimagination.jgn.TCPMessageServer;
public class DFTestTimeSynchronizationclient {
public static void main(String[] args) throws Exception {
MessageServer server = new TCPMessageServer(new InetSocketAddress(20000));
JGN.createThread(server).start();
MessageClient client = server.connectAndWait(new InetSocketAddress(
10000), 5000);
if (client == null)
throw new IOException("Connection not established!");
System.out.println("Connection established!");
for (int i = 0; i < 100; i++) {
System.out.println(client.synchronizeTimeAndWait(500));
Thread.sleep(50);
}
System.out.println("finished!!!");
}
}