socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

sync on unload doesn't work for XHR-Polling or JSONP

Open crickeys opened this issue 14 years ago • 2 comments

I can't get the disconnectSync to actually disconnect the client if they close their browser in chrome (haven't tried elsewhere yet). To reproduce:

  1. Start a socket server with only XHR polling or only JSONP polling transports and debug log on
  2. Open connection in chrome (You'll see the handshake and connection in the debug log
  3. Close the browser tab
  4. Nothing registers on the server side.

crickeys avatar May 13 '12 07:05 crickeys

You can ask the client to notify the server about disconnect by turning on the flag sync disconnect on unload:

var socket = io.connect('http://localhost', {
  'sync disconnect on unload': true
});

This solution has some shortcomings though, see this pull request for more details.

See also a related StackOverflow question & answer.

bajtos avatar Aug 05 '13 18:08 bajtos

Is there a server-side solution for this issue? While the client option works on desktop browsers, I'd still prefer not to rely on the client to inform the server of a disconnect.

mattcodez avatar Apr 09 '14 18:04 mattcodez