如何在socket.io中检测客户端的套接字服务器授权失败?

我想使用socket = io.connect()将一个js套接字客户端连接到socket.io服务器。 但是在服务器端,我使用io.use()方法来检查这个套接字连接是否包含cookie。 如果套接字初始握手不包含cookie,则限制套接字服务器上的请求进行连接。 通过传递next(new Error("Authentication Error")) 。 但即时通讯不能捕捉客户端的这个错误。 我想通知客户端无效的login会话并重新login。

谢谢

谢谢Andrey …我成功了

 socket.on("error", function() { //function to perform on occurance of authorisation failure }) 

我想你需要听connect_error

 socket.on('connection_error', function(data) { // data here should be an Error object sent by server }); 

文档是可怕的,但这里有一点提示(在这里find):

Errors passed to middleware callbacks are sent as special error packets to clients.