python - Detecting if client has disconnected -


i developing web-application on gae using webapp2 web framework. 2 player game multiple instances of game being played simultaneously. server acts path communicate game playing data between 2 computers , validate it. the clients communicate server http request only.

to this, make table in store ip address, userid (by using cookies), , username (if user has signed up) of both users , address game instance playing.

until , unless game finishes (either player wins) not remove entry in table, realized, if one(or both) of players disconnects before game ends or there network error causing one(or both) of players quit.

how come know game no longer active, can remove entry table , notify player still waiting opponent move?

you can:

  • add last_action = datetimeproperty(auto_now=true) in user model
  • add ended = datetimeproperty() in game model
  • create method search users last_action < - x minutes, , set ended property of games users
  • create method delete games ended since y minutes
  • run methods periodically via tasks , cron

but if clients can execute javascript, better have @ channel service.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -