我无法连接到本地主机上的wss。我有以下设置:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
我启动了wss服务器
const server = https.createServer({
cert: fs.readFileSync('./cert.pem'),
key: fs.readFileSync('./key.pem'),
passphrase: 'ledtesting'
});
const wss = new WebSocket.Server({ server });
server.listen(8000, 'localhost',function listening () {
console.log(server.address().port);
const ws = new WebSocket(`wss://localhost:${server.address().port}`, {
rejectUnauthorized: false
});
});
我正在运行一个electron应用程序,有一个网页可以使用以下工具连接到此web socket服务器:
var localsockUrl = "wss://localhost:8000/";
var localsocket = new WebSocket(localsockUrl);
connection to 'wss://localhost:8000/' failed: WebSocket opening handshake was canceled
如何在electron应用程序上访问localhost上的wss?