Laravel / Forge / digitalOcean; Socket.io; SSL;客户端连接错误

时间:2018-08-21 18:11:50

标签: laravel express ssl redis socket.io

此Socket代码在localhost和带有'http'的服务器上都有效,但是在'https'上停止了工作

你能帮忙吗?

这是socket.js代码->

 var app = require('express'));
var ssl= "true";

if( ssl == "true"){
   var fs = require('fs');
   var https = require('https');
   var options = {key: fs.readFileSync('/etc/nginx/ssl/peanuts.com/386351/server.key'),
       cert: fs.readFileSync('/etc/nginx/ssl/peanuts.com/386351/server.crt'),
 }
   var server = https.createServer(options, app)
}else{
   //var server = require('http').Server(app);
   var server = require('http').createServer(app);
}

var io = require('socket.io')(server);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('test-1', function (err, count) {
});
redis.on('message', function (channel, message) {
   console.log('Message Recieved: ' + message);
   message = JSON.parse(message);
   io.emit(channel + ':' + message.event, message.data);
});
server.listen(3000, function () {
   console.log('Listening on Port 3000');
});

这是客户端中的连接->

var socket = io.connect('https://peanuts.com:3000',{secure:true});
socket.on('test-1:App\\Events\\BidMade', function (data) {}

0 个答案:

没有答案