I want to close a specific socket

Asked 2 years ago, Updated 2 years ago, 85 views

This is the person who creates the chat application in NodeJS (SocketIO).

We use the following methods to send to specific users:

io.to(socket.id).json.emit('message',message);

How do I close a socket for a particular user using the socket ID?

javascript node.js websocket

2022-09-30 10:39

1 Answers

io.sockets.connected [socket.id].disconnect();

Namespace#connected seems to be used to reference Socket from Socket#id.
Therefore, if you do not use Namespace, use the alias Server#sockets to the default Namespace / as shown above.
Official server-side API documentation


2022-09-30 10:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.