Socket.io和Express与ERR_SSL_VERSION_OR_CIPHER_MISMATCH

时间:2017-11-23 00:02:07

标签: node.js express ssl https socket.io

我正在尝试在我的服务器中使用套接字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上工作?

1 个答案:

答案 0 :(得分:0)

您应该传递任何内容,>>> import json >>> s = """[ ... { ... "time": "30\/3", ... "tag": "I\u00c3\u00b8" ... }, ... { ... "time": "12\/4", ... "tag": "Da" ... } ... ]""" >>> json.loads(s) [{'time': '30/3', 'tag': 'Iø'}, {'time': '12/4', 'tag': 'Da'}] optionshttps.Server

app