Socket.IO – 从客户端发送的消息在服务器和客户端上失败

我正在使用Socket.IO连接从服务器到客户端的实时数据通信平台。 服务器运行的是Node.JS,客户端是使用Atom的Electron的网页forms的桌面应用程序。

我很好地接收客户端的消息,但是当我尝试发送消息时,通过以下格式:

window.socket.emit('embed',{'...'}); 

服务器触发error handling程序:

 socket.on('error',function(err) { console.log('client error: '+JSON.stringify(err)); }); 

我在我的日志中看到:

 client error: {} 

debugging客户端上的Socket.IO会在消息发送时显示日志:

 [14184:0511/184052:INFO:CONSOLE(1)] "socket.io-client:manager writing packet %j +10s", source: https://cdn.socket.io/socket.io-1.3.5.js (1) [14184:0511/184052:INFO:CONSOLE(1)] "socket.io-parser encoding packet %j +819ms", source: https://cdn.socket.io/socket.io-1.3.5.js (1) [14184:0511/184052:INFO:CONSOLE(1)] "socket.io-parser encoded %j as %s +0ms", source: https://cdn.socket.io/socket.io-1.3.5.js (1) [14184:0511/184052:INFO:CONSOLE(2)] "%cengine.io-client:socket %cflushing %d packets in socket%c +820ms", source: https://cdn.socket.io/socket.io-1.3.5.js (2) 

任何线索为什么这可能会发生?

编辑:

客户端和服务器都运行Socket.IO版本1.3.5。

此外,尝试使用console.loglogging错误对象导致在控制台中的这一行:

 [TypeError: Property 'undefined' of object #<Object> is not a function] 

我假设该函数绑定到服务器上的错误事件不旨在接受错误对象。

编辑:

在服务器端,执行这段代码来开始Socket.IO连接。

 var io = require('socket.io')(1415); io.on('connection',function(socket) { console.log('connection'); socket.on('error',function(err) { console.log('client error: '+JSON.stringify(err)); console.log(err); }); socket.on('embed',function(obj) { var type = obj.type; var id = obj.id; console.log('--------------------------------------------'); // ... // Additional Application Logic }); }); 

客户端,这个代码运行:

 window.socket = io('http://localhost:1415'); // When the message is emitted, this code is run. This code is run on a delay, and after messages have been received, so assume a connection is already established function(id) { var type = getType(id); window.socket.emit('embed',{id:id,type:type}); }(); 

编辑(再次):

其他消息可以成功发送和接收。

通过networking检查员networking面板检查原始networking数据显示:

错误