我收到了这个错误:
Error: Uncaught, unspecified 'error' event.
at WebSocket.EventEmitter.emit (events.js:73:15)
at Receiver.self._receiver.onerror (C:\programing\project\node_modules\ws\lib\WebSocket.js:566:10)
at Receiver.error (C:\programing\project\node_modules\ws\lib\Receiver.js:301:8)
at Receiver.processPacket (C:\programing\project\node_modules\ws\lib\Receiver.js:198:12)
at Receiver.add (C:\programing\project\node_modules\ws\lib\Receiver.js:89:3)
at Socket.firstHandler (C:\programing\project\node_modules\ws\lib\WebSocket.js:524:22)
at Socket.EventEmitter.emit (events.js:96:17)
at TCP.onread (net.js:397:14)
node-webkit 似乎运行了 2 到 4 个小时,然后我收到上述错误。我不确定我的 wifly 模块是否在 node-webkit 尝试将数据包发送回 wifly 模块时超时导致过早断开连接。或者,如果通过 web-socket protocal-76 发送的数据包已损坏,导致 webkit 模块无法理解正在发送的内容?我应该怎么做才能修复这个错误?
网络套接字代码:
var WebSocketServer = require('ws').Server, wss = new WebSocketServer({
port : 8080
});
wss.on('connection', function(ws) {
alert('connected!');
ws.on('message', function(message) {
//alert(message);
$('#wsData').val(message);
//console.log('received: %s', message);
});
ws.send('something', function(error){
alert('Send error' + error);
});
});
添加后:
ws.on('error', function(error) { console.log(error); });
我收到消息:保留字段必须为空 index.html:50
第 50 行代码:console.log(error);