Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
How to detect when a user leaves web-game lobby

I've a basic multiplayer web-game where players get matched in a lobby of 2 when they enter the website. I'm using nodejs and express for the server side.

I want the server to detect when a player "leaves" the lobby so that i can then match the remaining player in the lobby with someone else. Leaving should include closing the tab, the browser or refreshing the page.

I tried sending an ajax request from the client side when the "unload" or "beforeunload" events fire. However i found this to be pretty inconsistent and not reliable. I've seen people use websockets for managing such client-server communications but never used them. I thought of using a timer on the server side to see if a player stops replying which might do the trick. How should i go about implementing this and how do other multiplayer web-games solve this problem?

Details about my server-side if it helps: I'm currently using express-session to decide ID's of players. Once the players are in a lobby of 2, they send continuous (every 0.5 seconds) ajax requests to the server to get information about the other player.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda