JS前端< - > C ++后端通信(不同的服务器) [英] JS Frontend <-> C++ backend communication (different servers)

查看:296
本文介绍了JS前端< - > C ++后端通信(不同的服务器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作方式包括网络fontend和后台服务的一个项目。
网络前端是用户访问,并应与后台服务,这是写在C ++和(未来可能是多重的)运行在不同的机器上。

I am working on a project which consists of a web fontend and a background service. The web frontend is accessible by users and should communicate with the background service, which is written in C++ and runs on a (probably multiple ones in the future) different machine.

供参考:
后台服务器(称为在未来的后台)就像一个HTTP服务器和监听到一个特定的端口上的传入请求。

FYI: the background server (called 'backend' in the future) acts like a http server and listens to incoming requests on a specific port.

到目前为止,前端发送命令到与XML或JSON格式包含数据的简单的HTTP请求的后端。

So far, the frontend sends commands to the backend with simple http requests containing data in xml or json format.

好了,现在这里是我的问题:
由于在前端的用户输入数据,前端期望后端一些数据以将其显示给用户,或在我们的数据库内部使用。

Well, now here is my problem: Since the user inputs data in the frontend, the frontend expects some data from the backend to display it to the user or use it internally in our databases.

你能不能推荐任何方式来处理数据从后端到前端发送?

Can you recommend any ways to handle the data sending from the backend to the frontend?

我目前的想法:
后端获取形式的参照通知的URL,这是否有任何数据返回到前端,它可以调用在启动时的链接。该文件名为某处输入,输入的数据存储,例如内存缓存或只MEM-数据库。
我打算使用JavaScript编写的前端,也许使用类似Ember.js或Angular.js一个框架,它可以处理内部自动此类数据的更新。无论哪种方式,它应该更新前端的实时尽可能使用尽可能少的资源成为可能。

My current idea: The backend gets a link on startup, sort of a pingback url, which it can call if there is any data to return to the frontend. The called file inputs the incoming data somewhere to store, e.g. memcache or a mem-only database. I am planning to write the frontend in javascript, maybe using a framework like Ember.js or Angular.js, which can handle such data updates automatically internally. Either way, it should update the frontend as realtime as possible with using as little resources as possible.

是我目前的工作方法或者是纯粹的傻瓜?

Is my current approach working or is it purely stupid?

所以一般:
你能给我提示如何改善上述方案或建议其他任何approches如何实现这一目标?

So in general: Can you give me tips how to improve the above scheme or suggest any other approches how to achieve this?

我已经GOOGLE了这一点,但我发现<一个href=\"http://stackoverflow.com/questions/6314320/designing-javascript-frontend-c-backend-communication\">Designing JavaScript的前端&LT; - &GT; C ++后端通信,但他只是想在同一台机器上他的后台,我有不同的。

I already googled this, but all i found was Designing Javascript frontend <-> C++ backend communication, but he just wanted his backend on the same machine, i have different ones.

编辑:
我忘了最重要的细节(或所以我想):目前仅用于处理大量的客户之一后端实例。在前端的每个用户具有与客户机管理器(后端)相关的至少一个客户端。所以可能会有大量的数据从经理归国。

I forgot the most important detail (or so i'm thinking): there is currently only one backend instance which handles a lot of clients. Every user on the frontend has at least one client associated with the client manager (the backend). So there may be a lot of data returning from the manager.

在这里真正的问题(或至少我认为这是最大的)是我应该如何对返回的数据分发到每个单一的客户端。

The real problem here (or at least I think it is the biggest) is how i should distribute the returned data to each single client.

Padmak

推荐答案

我不认为熟悉C ++作为后端的Web服务,但如果你正在端口上监听和处理的URL(通过某种类型的控制器?),那么阿贾克斯将是最好的解决方案,你可以建立一个网址,从前端发布数据和从你的服务返回数据。我注意到您添加angular.js和ember.js作为标记。

I am not that familiar with C++ as a backend web service but if you are listening on a port and handling urls ( through some type of controller? ) then ajax would be the best solution, you could set up a url to post data to from the front-end and return data from your service. I noticed you added angular.js and ember.js as tags.

如果您使用的是他们,他们都有很大的框架,使用Ajax的工作,不知道烬但angular.js使用的资源,其身价谷歌搜索。

If you are using them they both have great frameworks for working with ajax, not sure about ember but angular.js uses "resources", its worth a Google search.

希望我正确地理解你的要求。

Hope I understood your request correctly.

此外,如果你正在使用的角度,你想实时觉得你应该看看模型和数据绑定和$表的方法。输入是在前端更改后,您可以发送Ajax调用立即,但是,您将要添加一些超时,所以你不经常将请求发送到后端。

Also if you are using angular and you want a real time feel you should look at models and data-binding and the $watch method. You could send ajax call after input is changed on front-end immediately, however, you will want to add some kind of timeout so you don't constantly send requests to the backend.

这篇关于JS前端&LT; - &GT; C ++后端通信(不同的服务器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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