Pregunta

Suppose 2 players are playing a game on 2 different browsers. The game states are stored in session variables, each browsers has a different session but the game object requires two players to move forth. The game manager makes sure two different sessions have signed on, before letting the players to proceed to the game pages. This would be a multi-page game, that has a sign in, pick colors, and end game. The cleanest way to disconnect the player is to wait till the game ends and the player can choose that they don't want to play anymore.

What if a player navigates away from the game pages, how can we let the other player know that the game has been terminated, so we can cleanly disconnect the remaining player to bring him back to the sign in page, in which we wait for a new player. How does the browser listen for a disconnect between two sessions?

¿Fue útil?

Solución

Sessions are not maintained on browser side. Neither browser is aware of session. You can have multiple strategies to achieve this result

  1. There are many client side javascripts available which can detect that the user is leaving the page and show appropriate warning or send the message to the server that the user has quit the page. They can also detect that the browser window is closing. You can use one of them.

  2. On server side, you will have to check the last response time of a user. when a user does not respond for a pre-defined time, you can consider him/her as disconnected.

  3. You can configure the session timeout in asp.net. You will also get an event in global.asax file when the session expires. This way, you will be able to determine that the user is disconnected.

I would recommend that you should use a combination of all three to achieve the result. If one of these fails, the other comes to play.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top