Synchronizing Multiplayer Startup

I'm currently developing a fighting game for the iPhone in my spare time, and I have most of the kinks in the basic engine worked out. Before I proceed with developing the mechanics of the game though, I would like to have a basic networking model functional. The main problem I'm facing in synchronizing the game state between two devices is the fact that the match does not start at the same time on either device.

Currently I am calculating latency between the devices and delaying the start of the match on the "host" device in an attempt to match when the other device receives the start message. Unfortunately, the latency rather wildly fluctuates between 10ms and 90ms, meaning that there is no guarantee that the games will start in sync even after compensating for latency. Does anyone here have an idea how I can accomplish this? Any help at all would be appreciated.

(Apr 27, 2011 03:46 PM)Oddity007 Wrote: If there's no server, then I imagine you could have both ends send a fixed time at which the two would be ready to start at to each other, then wait for the time that is the latest.

I thought about that soon after posting my initial question, and tried it out. Unfortunately, I've found that there is no way to guarantee that the two devices' internal clocks will be in sync with each other.

I may have messed up in my math somewhere, so here's some code to look at:

It's not clear to me that starting at the same wall-clock time helps you, but if it does:

A: this is "then"
A->B "tell me your clock"
B->A "this is my clock"
A: this is "now"
A: the clock value I just received from B is what his was at 0.5 * (now - then) ago.
(A can repeat several times and perform statistical analysis for greater accuracy if desired. It breaks down if the communication is *really* asymmetric, that is A->B takes significantly more or less time than B->A).
A: therefore the delta of his clock to mine is...