[英]PHP Websocket ERROR: net::ERR_SSL_PROTOCOL_ERROR using cloudflare
[英]Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR is thrown when trying establish and connect to a websocket server
如标题所示,建立和连接服务器时出现错误。 我正在使用一个名为simple-websocket的npm库来实现此目的。
在服务器端,我正在使用节点,而对于前端,我正在使用browserify捆绑节点模块。 我已经尝试过更改端口,并搜索了没有结果的修复程序。
这是我的节点代码:
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)
})
这是我的网络代码:
const Socket = require('simple-websocket')
exports.test = function() {
const socket = new Socket('wss://localhost:8181')
socket.on('connect', function() {
console.log('yes')
})
}
这是完整的错误:
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
如果有用,请使用以下浏览器代码: http : //www.filedropper.com/bundle_2
您创建的simple-websocket/server
实例不是在监听加密的/ wss / ssl连接,而是在监听标准的websocket连接。 您应该尝试使用ws://localhost:8181
(而不是wss://...
)连接到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.