node.js - 如何使用socket.io获取disconnect事件?

时间:2013-07-26 09:25:25

标签: javascript node.js javascript-events socket.io

有人可以告诉我如何通过socket.io xhr-pollingnode.js的{​​{1}}断续续订活动吗?

此示例不适用于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获取断开连接事件?

提前致谢;)

0 个答案:

没有答案