1

I am completely new to the socket.io and trying to get my feet wet by starting with examples on their home page. But all that i get in console after execution is this

debug - served static content /socket.io.js

My Server side code is this:

    var app=require('http').createServer(handler)
    , io = require('socket.io').listen(app)
    , fs = require('fs')
    app.listen(80);

    function handler (req, res)
    {

    fs.readFile(__dirname + '/index.html', function (err, data) 
    {
        if (err)
        {
               res.writeHead(500);
               return res.end('Error loading index.html');
        }
        res.writeHead(200);
        res.end(data);
       });
     }

    io.sockets.on('connection', function (socket) {
    console.log("connected");
    socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
    console.log(data);
    });
    })

And my index.html goes like this:

var socket = io.connect('document.location.href');

   socket.on('error',function(reason){
  // console.error("Error");


  });
  socket.on('connect', function () {
  console.log('connected');       
          socket.send('hi');

          socket.on('message', function (msg) {
                // my msg
                    });
                     });
             </script>

I googled about it and couldn't resolve the issue. I am on ubuntu with firefox.

beNerd
  • 3,314
  • 6
  • 54
  • 92

1 Answers1

2

If i'm not mistaken your error is here:

'document.location.href'

which shall be

document.location.href

I've just complete a simple example app for which I'll be soon writing a tutorial: https://github.com/dotcloud/socket.io-on-dotcloud

You can grab it (just clone it) and fool around with it to easy how to get started with socket.io with express 3. It is even ready to be push on dotCloud if you whish to share your app.

3on
  • 6,291
  • 3
  • 26
  • 22
  • Yes that changed some thing. M not sure if this is the expected output from this but here is what i get:info - socket.io started debug - served static content /socket.io.js debug - client authorized info - handshake authorized YU7ShJj3BCAdNdYrpPun debug - setting request GET /socket.io/1/websocket/YU7ShJj3BCAdNdYrpPun debug - set heartbeat interval for client YU7ShJj3BCAdNdYrpPun debug - client authorized for debug - websocket writing 1:: connected debug - websocket writing 5:::{"name":"news","args":[{"hello":"world"}]} – beNerd Aug 18 '12 at 07:32
  • yes the same output...also can you tell me how to stop the debug outputs from socket.io? – beNerd Aug 18 '12 at 07:37
  • Yeah it can be annoying: http://stackoverflow.com/questions/6807775/socket-io-remove-debug-mode – 3on Aug 18 '12 at 07:39