Thursday, 11 May 2017

Socket.io with Nodejs and windows10 connecting issue

I am new to nodejs. I have Nodejs on windows10. Then i created a folder inside Nodejs with a server.js file and install socket.io by command "npm install socket.io"

My server.js looks like

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

    app.listen(3000);

    /*
    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);
      });*/
    });

then i do node server.js and the operation gets stucked

https://ibb.co/fHTmt5



via zipzap