1

有人可以告诉我如何socket.io使用xhr-pollingin获取断开连接事件node.js吗?

此示例不适用于xhr-polling但适用于websockets..

/* Basics */

var express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server);

server.listen(1337, null);

io.set('transports', ['xhr-polling']); // If I change it to websockets it works!

// routing
app.get('/', function (req, res) {
res.sendfile("index.html");
app.use(express.static(__dirname));
});

var online_clients = 0;

io.sockets.on('connection', function (socket) {
    socket.on('disconnect', function() {
        console.log("SOMEONE LEFT");
    });
});

那么如何获得断开事件xhr-pooling呢?

4

0 回答 0