Error: Uncaught, unspecified "error" event. ([object Object])

Error: Uncaught, unspecified "error" event. ([object Object])

我正在尝试在收到套接字时推送通知。

服务器端:

if(data.handle.length > 0 && data.message.length > 0){
  io.sockets.emit('chat', data);
} else {
  socket.emit('error');
}

客户端:

socket.on('error', function(){
  $.amaran({
      'theme'     :'colorful',
      'content'   :{
         bgcolor:'red',
         color:'#fff',
         message:'Please enter your name, and message and try again.'
      },
      'position'  :'top right',
      'outEffect' :'slideBottom'
  });
});

error 事件 "reserved" 供 SocketIO 内部使用,因此您不应该将它用于您自己的任何事件。改用 data-error 之类的东西:

socket.emit('data-error');

socket.on('data-error', ...);