我最近在我的网站上启用了SSL,它有一个使用Socket.io的Node.js脚本。我已尝试将Socket.io设置为在HTTPS上运行,但在Chrome控制台中,它会在尝试从套接字中获取数据时报告404()GET错误
客户端代码:
var io = io.connect('https://domain.com:443');
服务器端
var connections=0;
var fs = require('fs');
var https = require('https');
var express = require('express');
var app = express();
var options = {
key: fs.readFileSync('./file.pem'),
cert: fs.readFileSync('./file.crt')
};
var serverPort = 443;
var server = https.createServer(options, app);
var io = require('socket.io')(server);
io.on('connection', function(socket){
connections=connections+1;
myconsolelog('[socket] a user connected. total connections: '+connections);
socket.emit('handshake',1);
socket.emit('online',connections);
request(steamstatusurl+'?pw='+accesspassword, function(error, response, body) {
//myconsolelog('steamstatus: '+body);
io.emit('steamstatus',body);
});
request(contentcreatorsurl+'?pw='+accesspassword, function(error, response, body) {
//myconsolelog('steamstatus: '+body);
io.emit('cc',body);
});
socket.on('disconnect', function(){
connections=connections-1;
myconsolelog('[socket] user disconnected total connections: '+connections);
socket.emit('online',connections);
});
});
server.listen(serverPort, function() {
console.log('server up and running at %s port', serverPort);
});
答案 0 :(得分:0)
经过几个小时的撞击我的脑袋后,我发现cloudflare正在拦截插座,并且数据不断传播,我创建了一个带有灰色云的子域,现在可以完全工作了