Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
Disconnect event not getting triggered on client's disconnection(sock.io)

I have:-

I'm currently working with a flask chatting web app. Where i've used flask_socketio for making active connection and sending data between server and clients.

1.On the server side

I made two socket events connect and disconnect this way :-

@socketio.on('connect')
def join_user():
    name = session['name']
    uid = session['uid']
    print(f"\nConnected:\nName: {name}\nUid: {uid}\n")
    join_room(uid)
    send(f"{name} joined the room")

@socketio.on("disconnect")
def lost_con():
    name = session['name']
    uid = session['uid']
    print(f"\nDisconnected:\nName: {name}\nUid: {uid}\n")
    leave_room(uid)
    send(f"{name} left the room")

@socketio.on("notify")
def notification(msg):
    print(msg)

Where:- name is the name of user and uid is the name for chatting room.

2.On the client side :-

<script src="https://cdn.socket.io/4.4.1/socket.io.min.js" integrity="sha384-fKnu0iswBIqkjxrhQCTZ7qlLHOFEgNkRmK2vaO/LbTZSXdJfAu6ewRBdwHPhBo/H" crossorigin="anonymous"></script>
    <script>
    var socket = io.connect('/');
    socket.on('connect', function() {
            socket.emit("notify", "New user connected");
     });
    socket.on('disconnect', function() {
            socket.emit("notify", " A user disconnected ");
    });
    </script>

I want:-

When ever a user get disconnected no matter whatever the reason is, it got kicked from the chatting room. Though it's working fine when I creatd a room from one tab and then join the same room with another tab, and then pressing back from the second tab(joined the room).

My problem:-

But while testing on android. On the Chrome browser, when i do the same and then instead of pressing back button and getting disconnected, I go to the opened tabs section and delete the opened tab with which i was joined the room I'm not getting any event invoked. I know deleting a opened tab doesn't provide the proper time on client side to invoke the socket.on(" disconnect"); function. But i should receive a disconnected request on the server side socketio.on("disconnected") but nothing happening on the server side too. That's preventing me to go further on that web app. How to got it working like I want something triggered on the server side on closing the tab directly. : (

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda