Captive Imagination
September 06, 2010, 09:07:25 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Check out the teaser site for the first official game by Captive Imagination: http://www.galaxiesbeyond.com
 
   Home   Help Search Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: JGN real time features  (Read 1310 times)
0 Members and 1 Guest are viewing this topic.
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« on: October 09, 2008, 04:55:42 AM »

Hello !

I'm testing JGN's real time features, and my bad I don't succeed in any way. For having readed all the relative posts, I think I quite get the way it should work, but I'm experiencing problems ...

         So to begin with :

      -I don't have a correct timeSynchronization: my client connect, but 1000 tests of long = ()synchronizetimeAndwait return me 0 beetween two pc whereas my ping oscillates beetween 2 and 5 ms ... I readed our guru discussion with not!an!exit and slowdive, and it seemed to work in 2007, but seems not to work anymore. As slowdive submitted a patch with no tests and the discussion closed with (slowDive) "I see. I'll think about it and let you know as soon as I have worked out some concept" I'm not sure this patch was a good thing ...

       -JGN's ping features report correct datas.

        -I extended ChatClient and chatServer tests to display the timestamp (chat message implements time stamped message) but I get a -1 timestamp, this time I'm not sure I get the way to make it work. Displaying the timestamp is the only change I made to the orginial tests, so what am I missing ?

Thank you for helping :-)

Kine
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #1 on: October 09, 2008, 07:36:40 AM »

You're checking the timestamp upon receipt of messages?  They are TimestampMessages?

Sorry I'm not more help right now...I've got a lot of other things on my plate at the moment.
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #2 on: October 10, 2008, 04:44:59 AM »

Quote
I extended ChatClient and chatServer tests to display the timestamp (chat message implements time stamped message) but I get a -1 timestamp, this time I'm not sure I get the way to make it work. Displaying the timestamp is the only change I made to the orginial tests, so what am I missing ?

       I made a few more tests (with both UPD and TCP connections), and the "implements timestampmessage" runs fine only if my message doesn't "implement certifiedmessage" ( on JGNServer+JGNClient).


Still testing timeSynchronization ... :-)
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #3 on: October 10, 2008, 07:36:26 AM »

interesting...it's possible there's a bug that's making CertifiedMessage exclusive.  If you're always sending through TCP then the message doesn't need to be Certified.
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #4 on: October 10, 2008, 08:50:30 AM »

Can you also provide a test case for validation?
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #5 on: October 10, 2008, 12:02:47 PM »

Sorry I was wrong again:

Here is what I think may be good :

Code:
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  Smiley
Kine

Code:
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();

}
}

Code:

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!!!");

}
}
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #6 on: October 10, 2008, 03:28:01 PM »

I would like to submit a patch, eclipse tries desperatly to connect to the svn ... but it doesn't work ...  Huh
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #7 on: October 10, 2008, 05:02:46 PM »

what do you mean? You want to commit directly to the repository?
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #8 on: October 13, 2008, 06:06:29 AM »

Hi !

Quote
what do you mean? You want to commit directly to the repository?
----> no, sorry, I wanted to have a fresh jgn copy but my svn was the jgn's old one

I've changed my view and I now think what you want exactly is a clock difference between to computers, and not a delayed difference.
Here is what I propose:
We calculate a real time difference by doing:  clokdifference = remotetime - System.gettimeinmilli,
but as the remote time is obsolete of a one way trip, we finally must do clockdifference = (remotetime + onewaytriptime) - system.gettimemilli
where onewaytriptime is : onewaytriptime = (System.gettimeinmilli - m.getLocaltime)/2.
In case the client and the server are on the same computer, we get negative results, because the lag can be made of 4/5 in one way and 1/5 the other and to avoid this, if the three times are ordered, we are forcefully on the same pc then we force the clock difference to 0.

And that's all the correction we can get from a single roundtrip synchronization.

Code:
Index: src/com/captiveimagination/jgn/InternalListener.java
===================================================================
--- src/com/captiveimagination/jgn/InternalListener.java (revision 1258)
+++ src/com/captiveimagination/jgn/InternalListener.java (working copy)
@@ -141,17 +141,21 @@
  myClient.getMessageServer().getConnectionController().negotiate(myClient);

  }

  } else if (message instanceof TimeSynchronizationMessage) {

- TimeSynchronizationMessage m = (TimeSynchronizationMessage)message;

- boolean responseDesired = true;

+ TimeSynchronizationMessage m = (TimeSynchronizationMessage) message;

  if (m.getRemoteTime() != -1) {

- long lag = m.getLocalTime() - System.currentTimeMillis();

- m.getMessageClient().setTimeConversion((m.getLocalTime() - System.currentTimeMillis()) - lag);

- responseDesired = false;

+ long actualTime = System.currentTimeMillis();

+ long lag = (actualTime - m.getLocalTime()) / 2;

+ if (actualTime >= m.getRemoteTime()

+ && m.getRemoteTime() >= m.getLocalTime())

+ m.getMessageClient().setTimeConversion(0);

+ else

+ m.getMessageClient().setTimeConversion(

+ (m.getRemoteTime() + lag - actualTime));

  }

  if (m.isResponseDesired()) {

- m.setRemoteTime(m.getLocalTime());

- m.setLocalTime(System.currentTimeMillis());

- m.setResponseDesired(responseDesired);

+ m.setRemoteTime(System.currentTimeMillis());

+ m.setLocalTime(m.getLocalTime());

+ m.setResponseDesired(false);

  m.getMessageClient().sendMessage(m);

  }

  } else if (message instanceof PingMessage) {



It runs fine here, check it with the above tests

See you

Kine
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #9 on: October 13, 2008, 03:50:41 PM »

Looks good.
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #10 on: October 15, 2008, 11:41:40 AM »

commited
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.219 seconds with 22 queries.