基于网络浏览器的 GUI
我正在 Linux 中开发一个与硬件交互的应用程序。要求之一是在 Web 浏览器中创建 GUI。该应用程序将基于 C++。我不熟悉网络相关的东西,所以我想知道是否可以做这样的事情(目前它是一个控制台应用程序从 txt 文件/cmd 行获取输入)。 gui 将很简单,使用按钮并在浏览器上显示应用程序的输出消息。我想知道涉及哪些技术/语言以及如何完成。我读过一些想法,但还没有找到任何具体的东西。如果您对这些有任何想法或更好的建议,请分享
- 在后台运行应用程序并与浏览器通信?
- 直接从浏览器调用库函数?
还有其他想法吗?
I am working on an application in Linux which will interfaces with hardware. One of the requirements is to create the GUI in Web-browser . the application will be c++ based. I m not familiar with web realted stuff so i want to know Is it possible to do such a thing (currently it's a console application take input from txt file/cmd line). gui will be simple using button and showing output messages on browser from the application. i want to know which technologies/languages are involved and how can it be done. some of the idea i read but havn't found anything concrete yet. if u have any idea about these or a better suggestion please share
- run the app in background and communicate with browser ?
- call library functions directly from browser ?
any other idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我首先会设置一个常规 HTTP 服务器,例如 lighttp 或 Apache httpd。
你说你已经有一个可以完成实际工作的命令行程序 - 作为第一步,我将重用它,并配置 Web 服务器以使用 CGI 调用你的程序 - 请参阅例如 http://httpd.apache.org/docs/2.2/howto/cgi.html for apache
最后,我'选择一些具有 Ajax 功能的 javascript 框架(例如 jQuery 或 YUI)来向服务器发出请求,以从网页内调用 CGI 脚本。您还可以创建一个基于表单的 Web 应用程序,无需 ajax 或任何框架,但这需要您在程序中填充各种逻辑来生成 HTML 页面。通过使用 Ajax,您可以按原样保留命令行应用程序,并使用 JavaScript 解析它给出的任何响应,然后使用它以对用户有意义的方式动态更改网页。
如果这一切都有效,那么我会尝试找出如何打包所有这些组件。也许您只是想创建一个包含所有程序的简单存档,或者您可能想实际上将网络服务器嵌入到您的程序中。或者,您可能想反其道而行之,将您的程序重写为可以插入网络服务器的 ISAPI 模块。或者,如果集成度不够,您可以编写自己的(部分)HTTP 服务器。这真的取决于你(我可能会花时间和精力来搜索最精简、最简单的现有开源 http 服务器并使用它)
无论如何,前面的步骤不会白费。最有可能的是,开发网页将成为工作的重要组成部分,因此我可能会首先使用古老的 CGI 技巧创建一个快速但肮脏的工作解决方案,然后开发网页以满足我的要求。那时,您只需将所有程序放在一个存档中就已经可以拥有一个可接受的可分发解决方案(当然您也必须调整网络服务器的配置,例如更改默认端口,这样就不会干扰现有的网络服务器。)之后我会花时间创建一个更加集成的奇特解决方案。
I would start by setting up a regular HTTP server, like lighttp or Apache httpd.
You say you already have a command line program that does the actual work - As a first step, I would reuse that, and configure the web server to call your program using CGI - see forexample http://httpd.apache.org/docs/2.2/howto/cgi.html for apache
Finally, I'd pick some javascript framework like jQuery or YUI with Ajax capabilities to do requests to the server to call the CGI script from within a webpage. You could also create a form-based web application without ajax or any framework, but that would require you to stuff all kinds of logic in your program to generate HTML pages. By using Ajax, you can leave the command line application as is, and parse any responses it gives with javascript, and then use that to dynamically change the webpage in a way that would make sense to the user.
If this all works, then I would try to figure out how to package all these components. Perhaps you just want to create a simple archive with all the programs inside, or maybe you want to go as far as actually embedding the webserver in your program. Alternatively, you may want to do it the other way around and rewrite your program as an ISAPI module that you can plug into your webserver. Or if that's not integrated enough still you could write your own (partial) HTTP server. That's really up to you (I'd probably spend time and energy on searching for the leanest, meanest existing open source http serverr and use that instead)
At any rate, the prior steps won't be lost work. Most likely, developing the web page is going form a substantial part of the work, so I would probably create a quick and dirty working solution first using the age-old CGI trick, and then develop the webpage to my satisfaction. At that point you can already have an acceptable distributable solution by simply putting all programs in a single archive (of course you would have to tweak the webserver's configuration too, like changing the default port so it won't interfere with existing webservers.) Only after that I would spend time on creating a more integrated fancy solution.
我最终使用了 Wt,尽管我会更新以供将来参考。
I ended up using Wt though I'd update for future reference.
以下是我的想法,按复杂程度排序对我来说:
创建一个可以通信的简单服务器端语言 (PHP/Python) 网站与您的应用程序(即启动并处理返回)
修改您的使应用程序拥有一个刚刚打出 HTML 的内置 Web 服务器(通过 URL 获取的命令行参数)
修改应用程序以发布 JSON 并在简单的 HTML 页面上使用 javascript 将其拉入。
修改应用程序以发布
您可以编写一个 Java小程序(正如您已标记此线程),但我认为您会浪费时间。如果您愿意花 10 分钟查找一些简单的命令,这可能会非常简单。
These are how I thought of doing this, in order of complexity for me:
Create a simple server-side-language (PHP/Python) website that can communicate with (ie launch and process the return of) your application
Modify your application to have a built-in webserver that just punched out HTML (command line parameters taken through the URL)
Modify the app to publish JSON and use javascript on a simple HTML page to pull it in.
You could write a Java applet (as you've tagged this thread) but I think you'd be wasting time. This can be quite simple if you're willing to spend 10 minutes looking up a few simple commands.
12年后,基于Web浏览器的GUI开始出现,WebUI就是其中之一。
After 12 years, web browser-based GUI started to appear, WebUI is one of them.