Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js geddy带有socket.io错误_Node.js_Socket.io_Geddy - Fatal编程技术网

Node.js geddy带有socket.io错误

Node.js geddy带有socket.io错误,node.js,socket.io,geddy,Node.js,Socket.io,Geddy,我正在使用geddy框架(基本聊天示例)开发一个实时应用程序。但是,当客户端尝试建立连接时,我会发现错误 以下是服务器端代码(在init.js文件中): 以及客户端代码: $(document).ready(function(){ startSockets(); }); function startSockets(){ var socket = io.connect('http://localhost:4004'); socket.on('new', function (dat

我正在使用geddy框架(基本聊天示例)开发一个实时应用程序。但是,当客户端尝试建立连接时,我会发现错误

以下是服务器端代码(在init.js文件中):

以及客户端代码:

$(document).ready(function(){
    startSockets();
});

function startSockets(){
  var socket = io.connect('http://localhost:4004');
  socket.on('new', function (data) {
    alert(data);
    //socket.emit('newMessage', { my: 'data' });
  });
}
当我尝试连接到localhost:4004/时,我收到下一个警告:

   debug - setting request GET /socket.io/1/websocket/G_GapksVv1J4iBZIUVe3
   debug - set heartbeat interval for client G_GapksVv1J4iBZIUVe3
   debug - websocket writing 7:::1+0
   warn  - client not handshaken client should reconnect
   info  - transport end (error)
   debug - set close timeout for client G_GapksVv1J4iBZIUVe3
   debug - cleared close timeout for client G_GapksVv1J4iBZIUVe3
   debug - cleared heartbeat interval for client G_GapksVv1J4iBZIUVe3
   debug - discarding transport
除此之外,Chrome控制台还出现以下错误:

WebSocket is closed before the connection is established. 

我不知道是什么引起这些。有什么想法吗?

问题是Socket.io启动后需要连接到服务器,而服务器只有在init.js中的代码运行后才会启动。现有内置RT代码(从Geddy v0.11开始)中的当前(hacky)解决方案是将此类代码放入config目录中的after_start.js文件中,Geddy在服务器启动后运行该文件。在这种情况下,这也应该作为一种解决方法,您自己将Socket.io连接到服务器

这显然并不理想,v0.12的一个主要目标是修复RT集成,使其更加可用和有用。如果你对这应该是什么样子有意见,一定要在IRC(Freenode.net上的#geddy)或邮件列表()上找到我们

WebSocket is closed before the connection is established.