Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force client disconnect from server with socket.io and nodejs

Tags:

socket.io

Is there any way to disconnect a client with SocketIO, and literally close the connection? So if someone is connected to my server, and I want to close the connection between them and my server, how would I go about doing that?

like image 288
Daniel Kenney Avatar asked Oct 23 '22 11:10

Daniel Kenney


People also ask

How do I remove Socket.IO from client side?

var socket = io. connect('http://localhost:3000/test'); socket. on('disconnect', function () { console. log('disconnect client event....'); }); socket.

How do I use Socket.IO in client side?

var socket = require('socket. io-client')('ws://ws.website.com/socket.io/?EIO=3&transport=websocket'); socket. on('connect', function() { console. log("Successfully connected!"); });

How do you close a client socket?

If you want the server to close the connection, you should use shutdown(cfd, SHUT_RDWR) and close(cfd) after, NOT close(lfd) . This lets the lfd socket open, allowing the server to wait at the accept for the next incoming connection. The lfd should close at the termination of the server.


1 Answers

Edit: This is now possible

You can now simply call socket.disconnect() on the server side.

My original answer:

This is not possible yet.

If you need it as well, vote/comment on this issue.

like image 162
nh2 Avatar answered Oct 26 '22 17:10

nh2