使用socket io和redis,Websocket无法在https上运行

时间:2018-04-19 14:56:00

标签: javascript node.js websocket socket.io

到目前为止,我正在运行一个带有简单网页的ubuntu服务器。我的websocket在页面没有安全(http)时工作,但由于它是安全的(https),websocket不再起作用。

这是我在socket.js文件中创建服务器...

var app   = require('https').createServer(handler);
var io    = require('socket.io')(app);
var Redis = require('ioredis');
var redis = new Redis();

// class declaration
var Redis = require('ioredis');

function handler(req, res) {
    res.writeHead(200);
    res.end('');
}

io.on('connection', function(socket) {});

/*
 |--------------------------------------------------------------------------
 | Redis InquirySent Channel
 |--------------------------------------------------------------------------
 |
 | Channel if an inquiry is sent,
 | an inquiry from a user to get permission to a specific stream
 |
 */
var redisInquirySent = new Redis();
redisInquirySent.psubscribe('inquiry-sent-channel-*');

redisInquirySent.on('pmessage', function(subscribed, channel, message) {
    message = JSON.parse(message);
    io.emit(channel + ':' + message.event, message.data);
});

// run server on port 3000
app.listen(3000, function () {
    console.log('Server running!');
});

我在Google开发者控制台/网络标签中收到此错误:

  

EIO = 3&安培;运输=轮询& T公司= MBUPI17

     

127.0.0.1/socket.io

使用以下标题:

  

常规:请求网址:

     

https://127.0.0.1:3000/socket.io/?EIO=3&transport=polling&t=MBUPI17

     

推荐人政策:no-referrer-when-downgrade

     

请求标题:显示临时标题接受: / 来源:

     

https://testpage.com Referer:https://testpage.com/inquiry用户代理:

     

Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,

     

像Gecko)Chrome / 65.0.3325.181 Safari / 537.36

0 个答案:

没有答案
相关问题