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