简体   繁体   中英

Socket.io and Express with ERR_SSL_VERSION_OR_CIPHER_MISMATCH

I'm trying to use socket Io in my server and when I try to acessas the service was I create the browser its given this error:

ERR_SSL_VERSION_OR_CIPHER_MISMATCH

Here is my server code:

 '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'); }); 

And here is the client code:

 <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> 

This certs and privatekey already is used on my domain and why is not working on socket.io and express?

You should pass nothing to express and options and app to https.Server :

const app = require('express')();
const https = require('https').Server(options, app);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM