Socket.IO不在外部工作

时间:2016-06-19 14:50:57

标签: node.js websocket socket.io

Node.js服务器

var app = require ('express')();
var http = require ('http').Server(app);
var io = require('socket.io')(http);
var users=0;
app.get('/',function(req,res){
    res.sendFile(__dirname + '/index.html');
});
io.on('connection',function(socket){
    users++;
    console.log('a user connected');
    socket.on('chat message', function(msg){
        io.emit('chat message', msg);
     });
     socket.on('disconnect', function(){
        users--;
        console.log('user disconnected');
      });
});
http.listen(3000, function(){
    console.log('listening on *:3000');
});

http://localhost:3000它可以保存index.html并且运行良好

http://104.155.198.127:3000响应(此网站无法访问) 104.155.198.127是真正的IP

0 个答案:

没有答案