简体   繁体   English

Socket.io与Node.js和Windows10的连接问题

[英]Socket.io with Nodejs and windows10 connecting issue

I am new to nodejs. 我是nodejs的新手。 I have Nodejs on windows10. 我在Windows10上有Nodejs。 Then i created a folder inside Nodejs with a server.js file and install socket.io by command "npm install socket.io" 然后我在Nodejs内使用server.js文件创建了一个文件夹,并通过命令“ npm install socket.io”安装了socket.io。

My server.js looks like 我的server.js看起来像

        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 然后我做节点server.js和操作卡住

https://ibb.co/fHTmt5 https://ibb.co/fHTmt5

What do you mean when you say the operation gets stucked. 当您说操作被卡住时,您是什么意思。 Have you tried connecting to the server with a web browser? 您是否尝试过使用Web浏览器连接到服务器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM