[英]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.
我正在使用一个名为simple-websocket的npm库来实现此目的。
On my server side I am using node and for my front end I am bundling the node modules using browserify. 在服务器端,我正在使用节点,而对于前端,我正在使用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 如果有用,请使用以下浏览器代码: 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. 您创建的
simple-websocket/server
实例不是在监听加密的/ wss / ssl连接,而是在监听标准的websocket连接。 You should be trying to connect to it with ws://localhost:8181
(not wss://...
). 您应该尝试使用
ws://localhost:8181
(而不是wss://...
)连接到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.