开发者

Synchronize time between two clients? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I am using zend framework with PHP to develop a web application where I have following requirements:

  1. When client1 tries to have a chat with the client2 a Confirmation box should appear saying "Your chat request has been sent to the Client 2. Please wait....." with remaining time in seconds that is 60 seconds at the start. And it should decrease by 1 开发者_如何学JAVAevery second.

  2. Then At the same time the Client2 should get a Confirmation box saying "Client1 requested a chat session with you. Wanna accept...?" with remaining time in seconds. If Client2 clicks on Yes then the chat session should start. If Client 2 clicks on No then the Confirmation box at both side Client1 and Client2 should disappear.

  3. If Client2 does not accept chat request from the Client1 and the remaining time reaches to 0 then chat session should not start and the confirmation box should be closed at both side.

  4. The remaining time should be synchronized at the both side.


Hope I am clear enough. Please suggest some code or sites that helps me.

Thanks in advance......


Synchronizing time solely depends on network speed.
If any of the client is having slow network, it will fail or there will be some lag.

Depending on practicality of application there are three approach. (Ascending order)
1. Store in Database, each time a request is made.
2. Store in File or Session and Schedule a dump into Database
3. Store In memory using Memcache so that there wont be any time consumption for Database Query or File Opening (File opening time is negligible but remember 3rd point is for very critical situation). Schedule a dump into database at later time.

In all the cases you have to take ServerTime into consideration not the Client's PC time. (And Yes you can get it from browser using Javascript)


I have never used the Zend framework, but I would suggest that you store in a database which client wants to contact another client and a timestamp for the timeout, and then have the clients periodically check the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜