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

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

问题描述

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



FYI:
后台服务器(以后称为后端)的作用就像一个http服务器,并侦听特定端口上的传入请求。



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



嗯,现在这里是我的问题:
由于用户在前端输入数据,前端预计后端的某些数据将显示给用户或在数据库中内部使用。



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



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



我现在的方法是正常工作还是纯粹是愚蠢的?



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



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



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



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



Padmak

解决方案

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



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



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



另外,如果你使用角度,而你想要一个实时的感觉,你应该看看模型和数据绑定和$ 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天全站免登陆