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

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

问题描述

我正在开发一个由web fontend和后台服务组成的项目。
web前端可以被用户访问,并且应该与后台服务通信,后台服务是用C ++编写的,并且运行在不同机器上的(可能是未来的多个)。



FYI:
后台服务器(以后称为后端)像http服务器一样,监听特定端口上的传入请求。



到目前为止,前端使用包含xml或json格式数据的简单http请求向后端发送命令。



好了,现在这里是我的问题:
由于用户在前端中输入数据,所以前端需要来自后端的一些数据显示给用户或在我们的数据库中内部使用。



您可以推荐任何方式来处理从后端到前端的数据发送?



我当前的想法:
后端在启动时获取一个链接,排序pingback url,如果有任何数据返回到前端。被调用的文件在某处存储输入数据,例如memcache或mem-only数据库。
我计划在javascript中编写前端,也许使用像Ember.js或Angular.js这样的框架,它可以在内部自动处理这样的数据更新。无论哪种方式,它都应该使用尽可能少的资源尽可能实时地更新前端。



我目前的方法是工作还是纯粹愚蠢?



所以一般情况下:
你能给我提示如何改进上述方案或建议任何其他审批如何实现这一点?



我已经google了这个,但我发现是设计Javascript前端< - > C ++后端通信,但他只是希望他的后端在同一台机器上,我有不同的。



编辑:
我忘了最重要的细节(或者我在想):目前只有一个后端实例处理很多客户端。前端上的每个用户都至少有一个客户端与客户端管理器(后端)相关联。所以可能有很多从管理器返回的数据。



这里真正的问题(或至少我认为这是最大的)是如何分发返回

解决方案

我不是熟悉C ++作为后端Web服务,但如果你正在侦听端口和处理URL(通过某种类型的控制器?)然后ajax将是最好的解决方案,你可以设置一个url,结束和返回您的服务的数据。我注意到你添加了angular.js和ember.js作为标签。



如果你使用它们,他们都有很好的框架使用ajax, .js使用资源,值得Google搜索。



希望我正确理解您的请求。



此外,如果你使用角度和你想要一个真正的时间感觉,你应该看看模型和数据绑定和$ watch方法。您可以在前端立即更改输入后发送ajax调用,但是,您将添加某种超时,因此您不会不断地向后端发送请求。


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.

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

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?

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?

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

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.

Edit: 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

解决方案

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.

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.

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天全站免登陆