我已经使用redis设置了节点js服务器和socket.io。 如果即时创建一个http服务器一切正常,但我切换到https请求和socket.io有轮询问题。它不断进行轮询,我不知道为什么......(通过http它不会连续轮询)
点击此处(最多可达10000+):http://i.stack.imgur.com/ZH2aV.png
只有当我使用https时我才会遇到这个问题...而且我不明白为什么他会这样做。
这是我的server.js
var app = require('express')();
var https = require('https');
var fs = require('fs');
var io = require('socket.io')(https);
var redis = require('redis');
var options = {
key: fs.readFileSync('xxxxxx'),
cert: fs.readFileSync('xxxxxx')
};
https.createServer(options, function (req, res) {
res.setHeader("Access-Control-Allow-Origin", "https://xxxxxxxxxxxxx.at");
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.setHeader("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
res.setHeader("Access-Control-Allow-Credentials", "true");
res.statusCode = 200;
res.end("hello world\n");
console.log("hi");
}).listen(3389, 'xx.xxx.xxx.xxx');
io.on('connection', function (socket) {
console.log("new client connected");
var redisClient = redis.createClient();
redisClient.subscribe('message');
redisClient.on("message", function(channel, notification) {
console.log("mew notifications in queue "+ notification + "channel");
socket.emit(channel, notification);
});
socket.on('disconnect', function() {
redisClient.quit();
});
socket.on('reconnecting', function() {
console.log("adsasd");
});
});
这是我的客户代码:
var socket = io.connect('<?php echo env('SOCKET_CONNECT_URL'); ?>', {secure: true});
socket.on('message', function (data) {
handleNotifications(data);
updateNotifications();
});
所以我的问题是,为什么socket.io不断轮询以及我的代码有什么问题或者我是否解决了错误?
Ps。:抱歉我的英语不好。