【问题标题】:socket auth failing when trying to connect尝试连接时套接字身份验证失败
【发布时间】:2015-12-18 05:02:06
【问题描述】:

它总是显示断开连接。

我尝试了所有的可能性。有时它会进行身份验证。

非常感谢任何帮助。

我正在使用 https://github.com/facundoolano/socketio-auth

var socket = io.connect('http://localhost');
socket.on('connect', function(){
  socket.emit('authentication', {username: "John", password: "secret"});
  socket.on('authenticated', function() {
    // use the socket as usual
  });
});

【问题讨论】:

    标签: node.js socket.io


    【解决方案1】:

    你是否检查了socket io auth中的超时选项

    var io = require('socket.io').listen(app);
    
    require('socketio-auth')(io, {
      authenticate: authenticate, 
      postAuthenticate: postAuthenticate,
      timeout: 1000
    });
    

    尝试更改超时值,直到成功。

    【讨论】:

      【解决方案2】:

      还添加事件处理程序以捕获任何错误或未验证消息。

      socket.on('unauthorized', function(err){
        console.log("There was an error with the authentication:", err.message); 
      });
      
      socket.on('error', function(err){
        console.log("There was an error ", err); 
      });
      

      【讨论】:

        猜你喜欢
        • 2010-09-12
        • 1970-01-01
        • 2021-01-18
        • 2014-05-29
        • 2014-07-05
        • 2014-05-18
        • 2020-07-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多