【问题标题】:Electron - Implement http module and socket.ioElectron - 实现 http 模块和 socket.io
【发布时间】:2021-06-24 21:28:39
【问题描述】:

是否可以使用 socket.io 在打开提供的链接时创建双向通信,并在电子 vue 应用程序中使用 ngrok 创建隧道?

// import dependencies - node context of electron see ipc
const { ipcMain } = require('electron');
const http = require('http');
? not sure on this part - socket.io implementation
const io = require('');

let server;
ipcMain.on('start-server', () => {
  server = http.createServer( (req, res) => {
   //serve a vue app where the external url is provided using localhost:15000 tunneling
...
  }).listen(15000);
});

我如何正确进行?

【问题讨论】:

    标签: node.js socket.io electron ngrok tunneling


    【解决方案1】:

    看来您需要指导。

    StackOverflow 的设计目的不是提供指导,而是回答具体问题。

    但是

    我认为你应该这样做:

    1. 创建一个简单的 Socket.io 应用程序。请参阅本教程:https://socket.io/get-started/chat
    2. 使用ngrok npm package 创建一个隧道,在您的端口15000 上连接到您的Socket.io 网络服务器。
    3. 创建一个加载您的 Ngrok url 的 Electon 应用程序。

    在这方面很难真正为您提供帮助,因为这是一个如此广泛的问题,但请尝试一下,并在必要时提出更多问题。

    【讨论】:

    • 我已经创建了一个 Electron 项目。 The problem 是 ngrok 模块在服务模式和生产中将无法工作!关于 socket.io,我过去已经为 heroku 实现了它,但你确认它的实现是相同的,我担心电子 socket.io 实现和普通 nodejs 服务器之间存在差异!
    • 据我所知,Socket.io 的实现应该是一样的。我没怎么用过 Ngrok,所以很抱歉。
    猜你喜欢
    • 2015-09-22
    • 2021-10-11
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 2018-12-09
    • 1970-01-01
    • 2020-07-25
    • 1970-01-01
    相关资源
    最近更新 更多