K
K
kr_ilya2019-06-18 13:37:36
Socket.io
kr_ilya, 2019-06-18 13:37:36

Socket.disconnect() closes current connection or all?

Perhaps a stupid question.
The phrase in the documentation baffled me.
Disconnects this client. If value of close is true, closes the underlying connection. Otherwise, it just disconnects the namespace.
Explain what this code closes

io.on('connection', (socket) => {
  setTimeout(() => socket.disconnect(true), 5000);
});

And this one:
io.on('connection', (socket) => {
  setTimeout(() => socket.disconnect(), 5000);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2019-06-18
@kr_ilya

true => disconnects the client completely
false => disconnects from the current namespace

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question