Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Designing Javascript frontend <-> C++ backend communication

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.

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.

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.

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

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?

Thanks in advance.

like image 792
Igor Avatar asked Jun 11 '11 05:06

Igor


People also ask

How do you communicate with frontend and backend?

Frontend and backend communicate with each other - via Http requests. The frontend will, for example, send entered data to the backend. The backend might then again validate that data (since frontend code can be tricked) and finally store it in some database.

Can JavaScript be used for both frontend and backend development?

Yes, JavaScript is used widely in frontend development, but in recent years is used for backend development too. Node. js (a JavaScript runtime) makes that possible by providing backend functionality.

How does JavaScript interact with backend?

It makes requests to your backend code and builds a HTML site by executing the JS part of the frontend code. Once it's done, the browser gets an HTML response, which was produced by JS code.

What is frontend and backend in JavaScript?

While front-end development is about making sites and web applications render on the client-side, back-end development is all about making these apps render server-side.


1 Answers

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

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.

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.

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.

like image 81
Amadan Avatar answered Oct 06 '22 00:10

Amadan