如何通过 Qt WebGL 流向多个用户提供 Qt 应用程序? [英] How to serve a Qt application to multiple users via Qt WebGL streaming?

查看:37
本文介绍了如何通过 Qt WebGL 流向多个用户提供 Qt 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qt 快速 WebGL 流 是一种技术,通过该技术,任何 Qt Quick(QML")应用程序都可以向通过网络浏览器连接的用户显示其用户界面.您所要做的就是在主机上像这样启动应用程序:

Qt Quick WebGL Streaming is a technology by which any Qt Quick ("QML") application can display its user interface to a user connecting via a web browser. All you have to do is to start the application like this on the host:

./my-qml-program -platform webgl:port=8080

这可行,但受设计限制,因此只能同时连接一个用户并查看用户界面.为此,他们引用了用户输入、查询 GPU 和安全性方面的问题(来源).

This works, but is limited by design so that only one user can be connected at the same time and see the user interface. As the reason for this, they quote problems with user input, with querying the GPU, and with security (source).

最初,Qt 开发人员希望通过从一个进程提供多个窗口来支持 WebGL 流中的多个用户:

Initially, the Qt developers wanted to support multiple users in WebGL streaming by serving multiple windows from one process:

如何支持并发?就像每个连接都有自己的 QGuiApplication 一样,还是只有一个?[…] 您创建了一个 QGuiApplication 和不同的窗口.当新客户端连接到 HTTP 服务器时,有一个信号通知.当信号被发射时,你创建了一个不同的 QWindow.窗口是独立的(来源)

How will concurrency be supported? Like does each connection get it's own QGuiApplication, or is there only one? […] You create a single QGuiApplication and different windows. There is a signal to notify when new clients connect to the HTTP server. When the signal is emitted, you create a different QWindow. The windows are independent (source)

然而,现在开发人员希望通过为每个用户启动一个进程来支持 WebGL 流中的多个用户.

Now however, the developers want to support multiple users in WebGL streaming by launching one process per user.

  • 我们正在努力将 HTTP 服务器与插件分离
  • 将提供专用的 HTTP Server 应用程序
    • 不是在同一个进程中运行所有用户,而是为每个用户生成一个新进程
    • 新进程将处理网络套接字

    (来源)

    从插件中解耦 HTTP 服务器";将意味着用 QHttpServer 替换它:

    "Decoupling the HTTP Server from the plugin" would mean replacing it with QHttpServer:

    我已经为这个 [QHttpServer] 模块计划了一些用例:在 WebGL 插件中更改当前的嵌入式 Web 服务器(和 WebSockets),以便轻松创建基于插件的自定义解决方案.(来源)

    I have planned some use-cases for this [QHttpServer] module: Change the current embedded web server (and WebSockets) in the WebGL plugin to make it easy to create your own custom solutions based on the plugin. (source)

    到目前为止,还没有实施任何解决方案.自己在 Qt WebGL 流中实现对多用户的支持,而无需等待 Qt 实现这一点,最简单的方法是什么?

    So far, no solution has been implemented. What is the simplest way to implement support for multiple users in Qt WebGL streaming myself, without waiting for Qt to implement this?

    推荐答案

    这里是一个使用负载均衡器的解决方案 Pen 使多个用户可以同时通过 WebGL 流访问 Qt 应用程序.它将传入连接转发到运行在同一主机上的多个 Qt 进程之一,每个进程都运行自己的嵌入式 Web 服务器.这种转发正是负载均衡器的工作,只是它通常将连接分配给多个主机.

    Here is a solution that uses the load balancer Pen to make a Qt application accessible via WebGL streaming to multiple users at the same time. It forwards an incoming connection to one of multiple Qt processes running on the same host, each of which running its own embedded web server. This kind of forwarding is exactly the job of a load balancer, just that it usually distributes connections to multiple hosts.

    警告:在我的测试中,Qt 5.12.3 中的 WebGL 流传输速度足够快,只能在本地网络中实际使用,而不是通过 Internet.所以你不能用它来以低廉的价格将 Qt 应用程序转换成 Web 应用程序".

    Caveat: In my tests, WebGL streaming in Qt 5.12.3 is fast enough for real use only in the local network, not over Internet. So you can't use it to "convert a Qt application into a web application on the cheap".

    这些说明适用于 Ubuntu 19.10、20.04 和其他基于 Debian 的发行版.

    These instructions apply to Ubuntu 19.10, 20.04 and other Debian based distributions.

    1. 在您的网络主机上安装 Qt 应用程序.

    在您的网络主机上安装 Qt WebGL 平台插件.例如,它不包含在 Ubuntu 19.10 发行版中.在这种情况下,您必须自己编译和安装.在 Ubuntu Linux 下,结果应该是以下文件:

    Install the Qt WebGL platform plugin on your web host. It is not contained in the Ubuntu 19.10 distribution, for example. In such a case, you'd have to compile and install it yourself. Under Ubuntu Linux, the result should be the following file:

    /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqwebgl.so
    

  • 启动 Qt 应用程序的多个进程.每个进程都应该为一个端口提供 Qt WebGL 流.在这里,我们开始了三个进程,但您可以根据自己的记忆开始尽可能多的进程.

  • Start multiple processes of the Qt application. Each should serve one port with Qt WebGL streaming. Here we start three processes, but you can start as many as fit into your memory.

    nohup myapplication -platform webgl:port=8080 &
    nohup myapplication -platform webgl:port=8081 &
    nohup myapplication -platform webgl:port=8082 &
    

  • 安装负载均衡器Pen.

    sudo apt install pen
    

  • 启动负载均衡器.请注意,使用 pen 80 ... 启动它,因此用户只需输入一个简单的 URl,例如 http://example.com/ 进入他们的网络浏览器以访问该应用程序.如果端口 80 已在使用中,您可以选择任何其他端口(例如,9090),使用 pen 9090 ... 启动负载均衡器,然后让用户访问类似的 URLhttp://example.com:9090/.还要注意列出的每个服务器进程的 :1:1 后缀,告诉 pen 最多只能将一个客户端连接到一个进程.

  • Start the load balancer. Note that with pen 80 … it is started so that the users only have to enter a simple URl such as http://example.com/ into their web browser to visit the application. If port 80 is already in use, you can choose any other port (say, 9090), start the load balancer with pen 9090 … and then let users visit a URL like http://example.com:9090/. Also note the :1:1 suffix for each server process listed, telling pen to only connect at most one client to one process.

    pen 80 localhost:8080:1:1 localhost:8081:1:1 localhost:8082:1:1
    

  • 测试设置.要进行测试,请从多个设备访问关联的 URL http://example.com/.您应该在每台设备上获得一个应用程序进程.不可能在 相同 设备上的两个并行浏览器选项卡中看到两个进程 - pen 然后会尝试将第二个这样的选项卡连接到与第一个相同的 Qt 进程选项卡,因为请求来自相同的 IP 地址.因此,您会在第二个选项卡中看到一个旋转轮,因为 Qt 进程只允许一个连接用于 WebGL 流.

  • Test the setup. To test, visit the associated URL http://example.com/ from multiple devices. You shoud be served one process of the application on each device. It is not possible to see two processes in two parallel browser tabs on the same device – pen would then try to connect the second such tab to the same Qt process as the first tab because the request comes from the same IP address. As a result, you'd see a spinning wheel in the second tab, because Qt processes only allow one connection each for WebGL streaming.

    改进

    此解决方案可以通过仅在客户端连接后按需启动 Qt 进程来进一步改进.这应该可以通过 systemd 套接字激活实现.

    这篇关于如何通过 Qt WebGL 流向多个用户提供 Qt 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆