admin管理员组

文章数量:1356328

I'm trying to use socket.io with existing application. My application runs on . Its using this code to connect to socket io server:

 var socket = io('https://localhost:3456/');
  socket.on('connect', function () {
    socket.send('hi');

    socket.on('message', function (msg) {
      // my msg
    });
  });

My socket.io server has this code to listen to ining connections:

var io = require('socket.io').listen(3456);

io.sockets.on('connection', function(socket) {
    console.log("dupa");
    socket.on('message', function() {});
    socket.on('disconnect', function() {});
});

dupa is never displayed on server side and in Chrome browser console I receive:

GET https://localhost:3456/socket.io/?EIO=3&transport=polling&t=1412901063154-0 net::ERR_SSL_PROTOCOL_ERROR 

How can I get this possibly working?

I'm trying to use socket.io with existing application. My application runs on https://somedomain.. Its using this code to connect to socket io server:

 var socket = io('https://localhost:3456/');
  socket.on('connect', function () {
    socket.send('hi');

    socket.on('message', function (msg) {
      // my msg
    });
  });

My socket.io server has this code to listen to ining connections:

var io = require('socket.io').listen(3456);

io.sockets.on('connection', function(socket) {
    console.log("dupa");
    socket.on('message', function() {});
    socket.on('disconnect', function() {});
});

dupa is never displayed on server side and in Chrome browser console I receive:

GET https://localhost:3456/socket.io/?EIO=3&transport=polling&t=1412901063154-0 net::ERR_SSL_PROTOCOL_ERROR 

How can I get this possibly working?

Share Improve this question edited Oct 10, 2014 at 0:47 xShirase 12.4k4 gold badges54 silver badges86 bronze badges asked Oct 10, 2014 at 0:34 spirytusspirytus 10.9k14 gold badges63 silver badges77 bronze badges 2
  • console.log("dupa"); looks quite familiar to me :D – matvs Commented Mar 31, 2020 at 18:38
  • Here is my answer to a similar problem with socket.io : stackoverflow./a/72293404/4106209 – PEC Commented May 19, 2022 at 5:11
Add a ment  | 

2 Answers 2

Reset to default 3

Change https to http

var socket = io.connect("http://localhost:4000");

Your socket server is not using SSL.

First, add the secure parameter to your client (maybe redundant with the https but SSL+socket.io does weird stuff sometimes):

var socket = io.connect('https://localhost', {secure: true});

Then, you need your socket to be secure too :

var privateKey = fs.readFileSync('YOUR SSL KEY').toString();
var certificate = fs.readFileSync('YOUR SSL CRT').toString();
var ca = fs.readFileSync('YOUR SSL CA').toString();

var io = require('socket.io').listen(3456,{key:privateKey,cert:certificate,ca:ca});

本文标签: javascriptCannot connect to secure socketio serverERRSSLPROTOCOLERRORStack Overflow