1

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

1
  • I came up with another approach: since the address of the managing server must stay secret, its impossible to let clients connect to it directly via things like Node.js. But if I install something like a proxy inbetween, I could follow this approach and do it like that. But it requires a lot of work to change the http server to a 'normal' tcp server I'd like some tips regarding this new solutions. Any? Commented Nov 25, 2013 at 10:03

2 Answers 2

0

There are 2 good ways to handle sending data from the backend to the frontend.

  1. client side polls the backend on some interval, this is a very common practice, but extremely inefficient if you are going to be making a million callbacks

  2. use websockets, http://en.wikipedia.org/wiki/WebSocket

Sign up to request clarification or add additional context in comments.

3 Comments

Since I am using only one manager which handles a lot of clients, my biggest problem is how to distribute the returned data to each client where they belong. I don't know if any of your recommendations could do this?
I'm not sure if I totally understand what the manager is. Correct me if I'm wrong, I'm trying to visualize it all, Joe Blow (User) in Chrome has 1+ clients associated with his user. Each client has it's own web server?
Bob has an account, logs into the frontend. He creates a new 'job'. The frontend connects to the backend, which creates a new subprocess. oops sent too fast. The manager then wants to send back data to the user. There is only one webserver in the manager which starts new clients and handles data.
0

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.

3 Comments

Very interesting, definitely good to know this! Though one problem remains: How can I deliver the data from the backend (which returns data for multiple clients at once) to the different frontend instances? Sorry for being a bit vague and/or unclear but it's hard to describe things like this as an non-native speaker^^
no problem, so if i understand correctly, you want it to update in real time across multiple front-end instances? if so you need something like web sockets, that is what you should start to investigate, i would offer some resources however, I don't know how that is handled with C++
Mmmh i think its more like this: multiple frontends are connected to only one backend, so how could i deliver the data from the backend to each frontend? Its so hard to describe :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.