exomic
exomic

Reputation: 486

Socket.IO Websocket server Maximum call stack size exceeded

I'm trying to get a websocket server working on my Debian linux server. I followed allot of tutorials but now I'm getting stuck with a error:

I'm following this tutorial http://codehenge.net/blog/2011/05/getting-started-with-node-js-and-socket-io-part-2/ Everyting works fine when trying to show (hello) but when I try to include Socket.IO I get this error.

info  - socket.io started

/usr/local/lib/node_modules/socket.io/lib/manager.js:0
(function (exports, require, module, __filename, __dirname) { /*!
^
RangeError: Maximum call stack size exceeded

Any ideas?

socketio-test.js

 var http = require('http')
, url = require('url')
, fs = require('fs')
, server;

server = http.createServer(function(req, res){
// your normal server code
var path = url.parse(req.url).pathname;
switch (path){
case '/':
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<h1>Hello! Try the <a href="/socketio-test.html">Socket.io Test</a></h1>');
res.end();
break;
case '/socketio-test.html':
fs.readFile(__dirname + path, function(err, data){
if (err) return send404(res);
res.writeHead(200, {'Content-Type': path == 'json.js' ? 'text/javascript' : 'text/html'})
res.write(data, 'utf8');
res.end();
});
break;

default: send404(res);
}
}),

send404 = function(res){
res.writeHead(404);
res.write('404');
res.end();
};

server.listen(8080);

// socket.io, I choose you
var io = require('/usr/local/lib/node_modules/socket.io').listen(server);

// on a 'connection' event
io.sockets.on('connection', function(socket){

  console.log("Connection " + socket.id + " accepted.");

  // now that we have our connected 'socket' object, we can 
  // define its event handlers
  socket.on('message', function(message){
        console.log("Received message: " + message + " - from client " + socket.id);
  });

  socket.on('disconnect', function(){
    console.log("Connection " + socket.id + " terminated.");
  });

});

Upvotes: 0

Views: 1261

Answers (1)

exomic
exomic

Reputation: 486

Update: I found the problem! I was using a unstable release of node. I simply reinstall using the stable one and now every is fine!

Upvotes: 1

Related Questions