2013-05-05 1 views
1

제목이 obvoius인데 인증되지 않은 사용자에게 몇 가지 오류 메시지를 다시 보내야하고 예를 들어이 메시지를 사용자에게 보내야하는 경우를 알아야합니다.socket.io의 허가되지 않은 사용자에게 오류를 보내야합니다.

당신이

채팅을 시작하고 난 그렇게하는 방법을 사용자 브라우저에서 인쇄 할 수있는 이름을 가지고 있겠지? 클라이언트 측 코드는 내가 콘솔에서 얻을이

//this is the client side code 
     var socket = io.connect('http://localhost', { resource: '/chat/app.js' }); 

     // on connection to server, ask for user's name with an anonymous callback 
     socket.on('connect', function(){ 
      // call the server-side function 'adduser' and send one parameter (value of prompt) 
      socket.emit('adduser') 
     }); 

    socket.socket.on('error', function (reason){ 
     console.log('Unable to connect Socket.IO', reason); 
    }); 

하지만 이유 같은 것을

어떻게 내가 메시지를 인쇄해야 Socket.IO 핸드 셰이크 오류를 연결할 수 없습니다

입니다 어떤 원인이 사용자의 승인을 얻지 못합니까?

는 manager.js의 오차 함수를 수정해야합니다 사용자에게 다시 오류를 보낼 수있는 서버 측 코드

 var io = require('socket.io').listen(80); 

     io.configure(function(){ 
      io.set('authorization', function (handshakeData, callback) { 
      // findDatabyip is an async example function 
      findDatabyIP(handshakeData.address.address, function (err, data) { 
       if (err) return callback(err); 

       if (data.authorized) { 
       handshakeData.foo = 'bar'; 
       for(var prop in data) handshakeData[prop] = data[prop]; 
       callback(null, true); 
       } else { 
//THIS IS THE MESSAGE ********************************************* 
       callback('you dont have any username to begin chat', false); 
       } 
      }) 
      }); 
     }); 
+0

function error (err) { writeErr(500, 'handshake error'); self.log.warn('handshake error ' + err); }; 

에서 당신은 여전히 ​​오류를받을 수 있나요? 즉, 항상이 오류가 발생합니까 아니면 findDatabyIP 호출에서 사용자를 찾을 수없는 경우입니까? –

답변

0

입니다 (socket.io \ lib 디렉토리 \ manager.js, 라인 768 약) findDatabyIP에서 콜백의 날짜가 일치 할 때이

function error (err) { 
    writeErr(500, /*'handshake error'*/ err); 
    self.log.warn('handshake error ' + err); 
    }; 
관련 문제