我正在尝试在服务器中使用套接字Io,并且当我尝试访问该服务时,由于出现此错误,我创建了浏览器:
ERR_SSL_VERSION_OR_CIPHER_MISMATCH
这是我的服务器代码:
'use strict';
const chalk = require('chalk');
const _ = require('lodash');
const fs = require('fs');
let options = {
key: fs.readFileSync("privkey.pem"),
cert: fs.readFileSync("cert.pem")
};
const app = require('express')(options);
const https = require('https').Server(app);
const io = require('socket.io')(https,{origins:'*:*'});
const bodyParser = require('body-parser');
const multer = require('multer'); // v1.0.5
const upload = multer(); // for parsing multipart/form-data
const sockets = {};
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
https.listen(3002, function () {
console.log(chalk.yellow("Serviço rodando na porta 3002"));
});
io.on('connection', function (socket) {
console.log(chalk.green("Cliente Conectado"));
sockets[socket.id] = socket;
socket.on('disconnect', function () {
console.log(chalk.red("Cliente Disconectado"));
delete sockets[socket.id];
});
});
app.post('/atualizador', upload.array(), function (req, res) {
_.each(sockets,function(socket,idSocket){
console.log(idSocket);
socket.emit('posicao',req.body);
});
res.send('Atualizador ON');
});
这是客户端代码:
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
<script>
const socket = io('https://localhost:3002/');
socket.on('posicao', function(msg){
console.log(msg);
});
</script>
此证书和私钥已在我的域上使用,为什么不能在socket.io和express上使用?
最佳答案
您不应传递任何内容来表达,而应将options
和app
传递给https.Server:
const app = require('express')();
const https = require('https').Server(options, app);
关于node.js - 带有ERR_SSL_VERSION_OR_CIPHER_MISMATCH的Socket.io和Express,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47445645/