Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS syncing time between devices

Tags:

time

ios

sync

Goal:

Given N devices, I would like to make them start an action which will take 10 seconds precisely and collect these datas in the end. Problem is, all of N devices should start this procedure in the same millisecond.

Advantage:

Since the data is going to be collected, I can run further detection about millisecond differences between devices. But this approach also requires another mechanism to detect such behaviour on the server-side.

Problem:

What should be my mechanism to sync the "start" time between N devices? Can we detect the difference between the device and the server clock (since it will give the same result as syncing time)?

like image 679
Bartu Avatar asked Nov 13 '22 09:11

Bartu


1 Answers

Yes.

Assuming that the messages are received within less than one second on all the devices:

The server sends a message to N devices. This message contains the timestamp of the server along with the time (in future) that the process should begin (e.g. 2000 msec).

Each device will check the timestamp of the server with its own timestamp and calculates the difference. Then starts a timer so that at the precise moment in the future it will start the process.

This way (in theory) the devices start a process at the exact same time. I said in theory, since this will work if there are no other apps running on the iOS device that already consume process and memory to interfere with your app.

like image 62
Armin Avatar answered Nov 15 '22 06:11

Armin