V
V
Vyacheslav Ruzanov2014-04-28 16:05:50
Node.js
Vyacheslav Ruzanov, 2014-04-28 16:05:50

Websocket on nodejs. Problem with "close" event?

I am writing a chat using websocket on nodejs. For websocket I use the module for ws . When the chat window is closed, the connection disconnection event on the server is triggered with a 10-30 second delay. How to fix it? The third day I'm struggling with a solution, I've run out of ideas.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Ruzanov, 2014-04-28
@ruzslav

Partially solved the problem. Such a script closes the websocket when the page is cleanly closed and the server immediately catches the event.

window.onunload = function(){
    ws.close();
};

For the case when the connection is interrupted not due to a clean closing of the browser or page, a delay of 10-30 seconds is not so terrible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question