有人可以告诉我如何通过socket.io
xhr-polling
与node.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
获取断开连接事件?
提前致谢;)