Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Are disconnect initiated by peer and disconnect caused by network problem handled differently? #2597

Closed
fangqiao opened this issue Jun 24, 2016 · 3 comments

Comments

@fangqiao
Copy link

Hi I am new to socket io. I am now working on an experiment project with socket io now.

I know socket io has built in automatic reconnect. On my case, I need to handle server initiated disconnect and network connection failure caused disconnect differently.

Is there a way to tell which is which? Are different events emitted?

Hope to find some answers. Thanks in advance.

@MasterJames
Copy link

MasterJames commented Jun 24, 2016

I believe you can call disconnect from the server.
#47
Or as you might imagine you can setup to tell a client to call it's disconnect like shown here.
http://www.unknownerror.org/opensource/Automattic/socket.io/q/stackoverflow/5048231/force-client-disconnect-from-server-with-socket-io-and-nodejs

socket.disconnect();

is suppose to work.

On the client you can specify how many times to try to reconnect and how often.
http://stackoverflow.com/questions/11632969/how-configure-reconnecting-in-socket-io

var socket = io({
        'reconnection': true,
        'reconnectionDelay': 1000,
        'reconnectionDelayMax' : 5000,
        'reconnectionAttempts': 5
    });

It maybe that you need to set reconnection:false at some point too so sending the message to the client to disconnect is a wise thing to do.

Also consider authorization if blocking
connect.utils.parseSignedCookie(handshakeData.cookie['express.sid'], 'secret')

from https://howtonode.org/socket-io-auth

@bratberg
Copy link

socket.disconnect();
is suppose to work.

You could also try socket.disconnect(true); - (closes the connection, not just the namespace)

https://github.com/socketio/socket.io/blob/b754cff2b415a8cbbf0f23c61824bcc69b078430/docs/API.md#socketdisconnectclose

@darrachequesne
Copy link
Member

For future readers: please see the documentation here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants