设计Javascript前端<-> C ++后端通讯 [英] Designing Javascript frontend <-> C++ backend communication

查看:80
本文介绍了设计Javascript前端<-> C ++后端通讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不远的将来,我将不得不制作一个具有C ++后端和Web前端(要求)的系统.目前,我对此并不了解.我认为,前端将触发数据传递,而不是后端-因此无需像彗星一样的东西.

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.

首先,我不喜欢从C ++生成HTML的选项. 因此,C ++后端必须与Javascript前端进行通信.我在这里看到的最简单的选择是Ajax.到目前为止,我认为应该没事.

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.

通过Ajax与C ++后端进行通信意味着后端应该能够处理HTTP.最好将提供实际数据和HTTP处理功能的后端分开.

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.

在这里,我看到了Node.js的位置.我对此有一个大概的了解,这是我所有怀疑的地方.

Here I see the place for Node.js. I got an overview of it and this's the place where all my doubts lie.

要在Node.js上具有HTTP处理服务器,该服务器将把数据后端"作为Node.js模块?我认为应该没问题-但我不确定我是否真的需要所有这些异步功能,所以可能有一些我不知道的更简单的选择?您将如何制作这样的系统?

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?

谢谢.

推荐答案

Node.js很难提供所有这些异步"功能.一旦您了解Node.js的工作原理,这就是Web服务的另一种观点,就像呼吸一样容易.

"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.

例如,我的同事们需要一种将C ++程序包装为Web服务的方法,但是该程序的启动成本很高,因此他们只想运行该程序的一个实例,循环运行即可,所有网络请求. Node.js中的整个过程只用了不到两个屏幕.

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.

可以在少于十行的Node.js中包装为每个请求调用的单个程序.不要将异步视为繁琐的事情-如果您接受它,Node.js就是很棒.

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.

也就是说,您可以走CGI路线,并以更标准的方式进行操作,最终结果将几乎相同. 可能会也可能不会派上用场.

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.

这篇关于设计Javascript前端<-> C ++后端通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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