socket.io强制断开客户端
我可能在这里做错了事,但是我无法理解这一点。
以下不起作用:
客户
$("#disconnectButton").click(function() { socket.emit("disconnect"); });
服务器
socket.on("disconnect", function() { console.log("this never gets called"); });
我不能手动从客户端调用断开连接事件吗? 因为以下工作:
客户
$("#disconnectButton").click(function() { socket.emit("whatever"); });
服务器
socket.on("whatever", function() { socket.disconnect(); console.log("this gets called and disconnects the client"); });
'disconnect'事件是Socket.io事件,如果使用emit来调用'disconnect',可能会导致其他问题
所以:
$("#disconnectButton").click(function() { socket.emit("disconnect"); });
更换:
$("#disconnectButton").click(function() { socket.disconnect(); });
- 我可以在节点js的networking套接字中使用的端口范围
- Web Audio Api:通过套接字从nodejs服务器播放数据块的正确方法
- 通过存储过程插入logging不工作(使用繁琐的MS SQL驱动程序)
- socket.io – 多个事件性能
- node.js的“net”包中的socket.write函数没有写入套接字
- 有没有可能有一个IRC客户端使用运行你自己的IRC服务器没有websockets网关的websockets?
- 使用代理的NodeJS简单UDP客户端服务器应用程序
- 通过自定义socket.io事件将Python客户端连接到Socket.io
- 在socket.io中断开连接后更新node.js中的数组