简体   繁体   中英

Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR is thrown when trying establish and connect to a websocket server

As is shown in the title, I am getting an error while establishing and connecting to a server. I am using a npm library called simple-websocket in order to achieve this.

On my server side I am using node and for my front end I am bundling the node modules using browserify. I have already tried changing the port and have searched for a fix with no results.

This is my node code:

const Server = require('simple-websocket/server')

const server = new Server({port: 8181})

new Promise((resolve, reject) => {
  server.on('connection', function(socket, request) {
    resolve({socket, request})
  })
}).then(data => {
  console.log(data)
})

This is my web code:

const Socket =  require('simple-websocket')

exports.test = function() {
  const socket = new Socket('wss://localhost:8181')

  socket.on('connect', function() {
    console.log('yes')
  })
}

And This is the full error:

WebSocket connection to 'wss://localhost:8181/' failed: Error in connection 
establishment: net::ERR_SSL_PROTOCOL_ERROR

bundle.js:6106 Uncaught Error: connection error to wss://localhost:8181
at WebSocket.Socket.self._ws.onerror (bundle.js:6106)
Socket.self._ws.onerror @ bundle.js:6106
error (async)
Socket @ bundle.js:6105
exports.test @ bundle.js:2841
9../middleware-comms/Listen @ bundle.js:2836
o @ bundle.js:1
r @ bundle.js:1
(anonymous) @ bundle.js:1

In case it is useful, Here is the browserified code: http://www.filedropper.com/bundle_2

The simple-websocket/server instance you're creating isn't listening for encrypted/wss/ssl connections, it is listening for standard websocket connections. You should be trying to connect to it with ws://localhost:8181 (not wss://... ).

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