代码之家  ›  专栏  ›  技术社区  ›  Pavan K

localhost上electron应用程序的WebSocket打开握手已取消

  •  0
  • Pavan K  · 技术社区  · 8 年前

    我无法连接到本地主机上的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?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Pavan K    8 年前

    在electron应用程序设置中,您可以通过以下方式忽略证书错误:

    app.commandLine.appendSwitch("ignore-certificate-errors");