views:

81

answers:

3

I'm developing a web site which will retrieve SMS messages that have been sent to a gateway. The gateway is accessed via an API, with the requests in the following format:

http://www.smsgateway.com/?login=myusername&password=mypassword&lasttime=1236164238

Notice that I'm having to track the last time messages were downloaded - only messages received after that time are returned.

The problem is that there's a time difference of about 5 minutes between the servers! Here's what's happening:

->User sends SMS; gateway server timestamps it at 11.00am (let's say actual time is 10.55am)

->My server requests all messages sent from 10.56 onwards - receives the above message and adds it to database

->My server requests all messages sent from 10.58 onwards - receives the above message and adds it again, since it is timestamped at 11.00am

->My server sends another request at 11.00 - receives the message and adds it to the database once more

So my problem is that the one original message is being received 3 times.

Changing my server's time is do-able, but not the remote servers.

How can I handle this without checking to see if the message is already in the database?

A: 

use a remote time service

Orentet
+3  A: 

When you receive the messages sent from 10.56 onwards, Check the last message time: Say 11:00 a.m, Then Next call only send only at 11:00 a.m because you had already received upto 11:00 a.m of server's time. This way you can reduce your polls. Even this will work for when Server's time is in the reverse condition.

ie) Check for last message's time:

in the next poll check from last message's time.

lakshmanaraj
Thanks for your help, this looks like the way forward.
John McCollum
+1  A: 

Your basic setup is racy, even if you keep the two servers' clocks in sync you will either lose or double up on messages that share timestamps (which can be many or few depending on timestamp resolution and message traffic).

You will either need a different API for accessing the messages or you have to request overlapping messages by requesting messages since latest_processed_timestamp - 1 and sort out the duplicates on your side.

Ronny Vindenes
Good point - I don't have the option of using a different provider, and the gateway won't push the messages to me, so I'll implement timestamp -1 and check for dupes. Thanks very much for your advice.
John McCollum