在我最近的将来,我将不得不制作一个具有 C++ 后端和 Web 前端的系统(要求)。目前,我对此了解不多。我认为前端将触发数据传输,而不是后端 - 所以不需要类似 Comet 的东西。
由于在该领域的经验可能很少,我非常感谢您对我所做的设计决策的评论。
首先,我不喜欢从 C++ 生成 HTML 的选项。
因此,C++ 后端必须与 Javascript 前端进行通信。我在这里看到的最简单的选择是 Ajax。我想到目前为止应该还可以。
通过 Ajax 与 C++ 后端通信意味着后端应该能够处理 HTTP。最好将提供实际数据的后端与 HTTP 处理功能分开。
在这里我看到了 Node.js 的位置。我对它有了一个概述,这就是我所有疑问所在的地方。
要在 Node.js 上拥有 HTTP 处理服务器,并将“数据后端”作为 Node.js 模块?我想,应该没问题 - 但我不确定我是否真的需要所有这些异步,所以可能有一些我不知道的更简单的选项?你会如何制作这样一个系统?
提前致谢。
In my nearest future I will have to make a system with C++ backend and web frontend (requirements). At the moment, I don't know much more about it. I think that Frontend will be triggering data delivery, not backend - so no need for Comet-like things.
Because of possibly little experience in this field, I'd really appreciate your comments about design decisions I made.
First of all, I don't like the option of generating HTML from C++.
So, C++ backend will have to communicate with Javascript frontend. Simplest option I see here is Ajax. I think it should be ok, so far.
Commucating through Ajax with C++ backend means that backend should be capable of handling HTTP. It'd be nice to separate backend which provides actual data from HTTP handling functionality.
Here I see the place for Node.js. I got an overview of it and this's the place where all my doubts lie.
To have a HTTP handling server on Node.js, which will have the 'data backend' as a Node.js module? I think, it should be ok - but I'm not sure that I really need all this asynchronization, so there may be some simpler options I'm not aware of? How would you make such a system?
Thanks in advance.
发布评论
评论(2)
“所有这些异步”并不是 Node.js 努力提供的额外功能。一旦您了解了 Node.js 的工作原理,这是一种不同的 Web 服务视图,就像呼吸一样简单。
例如,我的同事需要一种方法将 C++ 程序包装为 Web 服务,但该程序的启动成本很高,因此他们只想运行该程序的一个实例,循环运行,为所有 Web 提供服务请求。 Node.js 中的整个过程只用了不到两屏。
封装每个请求调用的单个程序只需不到十行 Node.js 即可完成。不要将异步性视为一件苦差事 - 如果您接受它,Node.js 就会很棒。
也就是说,您可以采用 CGI 路线,并以更标准的方式进行,最终结果几乎相同。 这可能会也可能不会派上用场。
"All this asynchronization" is not something that Node.js works very hard to provide as an extra. It is a different view of Web serving that is easy as breathing once you understand how Node.js works.
For example, my colleagues needed a way to wrap a C++ program as a web service, but the program had a significant start-up cost, so they wanted to run just one instance of the program, running in a loop, serving all the web requests. The whole thing in Node.js took less than two screenfuls.
Wrapping a single program that is called for each request can be done in less than ten lines of Node.js. Don't think of asynchronicity as a chore - if you embrace it, Node.js is awesome.
That said, you could go the CGI route, and do it in a bit more standard way, and the end result would be pretty much the same. This may or may not come in handy.
您是否考虑过 nginx、Apache 等的 CGI/FCGI 模块选项?
如果没有,那么我认为从它开始是有意义的。您的模块将处理 data/json 请求,其余部分将由 HTTP 服务器处理。
Did you consider CGI/FCGI module option with nginx, Apache, etc. ?
If not then I think it makes sense to start from it. Your module will handle data/json request and the rest will be handled by HTTP server.