Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

best c++ library in order to integrate c++ with web application

41 views
Skip to first unread message

kushal bhattacharya

unread,
Feb 18, 2017, 2:23:28 AM2/18/17
to
Can anybody suggest me the best c++ library which works really good in integrating c++ with html.So far i have come accross Wt and Cppcms but i really cant figure out whether using this would be worth it in terms of productivity.I want to integerate c++ just as a backend with html and writing html javascript css alongside it.
Thanks
Kushal

kushal bhattacharya

unread,
Feb 18, 2017, 2:27:24 AM2/18/17
to
To put it in other words i want to use c++ as backend for processing tasks from the client end just as php or any other server side scripting language does

Paavo Helde

unread,
Feb 18, 2017, 1:33:57 PM2/18/17
to
On 18.02.2017 9:27, kushal bhattacharya wrote:
> To put it in other words i want to use c++ as backend for processing tasks from the client end just as php or any other server side scripting language does

This would be HTTP, not HTML. Maybe you wanted to say that your
responses would mostly be in HTML?

For an HTTP server one can use Boost.asio, it's a great library. The
library itself covers only sockets and TCP, but there are examples
featuring a simple HTTP server which you can build on.

For producing HTML the simplest approach is to use std::string +=
operation and a couple of utility functions for quoting the content
properly. It is actually very easy to produce HTML, with a bit of
discipline this can be even somewhat readable.

Alternatively, you can build some XML tree in memory by using one of the
various XML libraries, and then dump it as an XML+HTML response to the
client. This method is more scalable than string concatenation (or PHP,
for that matter). A further development along those lines would involve
some XML templates in disk files which would be read in and parsed into
XML trees in memory, then adjusted as needed for a concrete response by
using the XML library, then dumped out to the client as before.

The simplest such XML library for C++ is TinyXML, it has the great
benefit that one can actually read its code and understand what it's
doing. A drawback is that it allocates each XML node separately, which
may be pretty slow for large XML-s (but this won't probably matter for
any HTML page meant for human consumption).

HTH
Paavo





Jorgen Grahn

unread,
Feb 19, 2017, 4:19:14 AM2/19/17
to
On Sat, 2017-02-18, Paavo Helde wrote:
> On 18.02.2017 9:27, kushal bhattacharya wrote:
>> To put it in other words i want to use c++ as backend for
>> processing tasks from the client end just as php or any other
>> server side scripting language does
>
> This would be HTTP, not HTML. Maybe you wanted to say that your
> responses would mostly be in HTML?

That's how I translated it, too.

> For an HTTP server one can use Boost.asio, it's a great library. The
> library itself covers only sockets and TCP, but there are examples
> featuring a simple HTTP server which you can build on.

I have the feeling he wants his C++ code to be part of the backend,
behind Apache httpd or similar web server.

Then he wouldn't implement HTTP-over-TCP, but something like CGI or
one of the other, newer alternatives which I have no experience with
(and which seem to replace each other on a monthly basis).

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Jerry Stuckle

unread,
Feb 19, 2017, 9:22:12 AM2/19/17
to
On 2/18/2017 2:27 AM, kushal bhattacharya wrote:
> To put it in other words i want to use c++ as backend for processing tasks from the client end just as php or any other server side scripting language does
>

There isn't any library I'm aware of for either C or C++ which does what
you want.

The problem is you not only have to handle sending the HTML, but you
have to interpret the incoming request, handling things like parameters
and cookies. You have to build and send header strings to the client,
and those must be sent before any HTML (and indicate an error if you try
to send a header after any output). If you want to store information on
the server across requests ($_SESSION values in PHP), you must handle it
yourself.

Web scripting languages do a lot for you behind the scenes. Of course,
you can do it all in C or C++, but it's going to take some work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

K. Frank

unread,
Feb 19, 2017, 10:21:44 AM2/19/17
to
Hi Kushal!

On Saturday, February 18, 2017 at 2:23:28 AM UTC-5, kushal bhattacharya wrote:
> Can anybody suggest me the best c++ library which works really good in integrating c++ with html.So far i have come accross Wt and Cppcms but i really cant figure out whether using this would be worth it in terms of productivity.I want to integerate c++ just as a backend with html and writing html javascript css alongside it.

I have used Wt for some toy projects and it seems to work well.
The Wt guys claim it is production quality and I have no evidence
to the contrary.

I would think that it would only make sense if you are willing to
write your front end (web site) in Wt. If you have an existing
front end (that you don't want to rewrite), or if know html /
javascript / css well (and want to keep using them), or you want
to use some other front-end framework or authoring tool, then
I don't think trying to use Wt for just the back end would be
worth the bother.

But if writing the front end in Wt works for you, then your
back-end c++ integration would be "automatic." Also, Wt comes
with its own built-in web server, if you want to use that, or
you can run Wt modules inside a number of existing web servers,
if you prefer.

So: Wt for the back end only? Probably not worth the bother.
Wt for the whole web application -- front and back? My toy
tests suggest that Wt could work well for this.

> Thanks
> Kushal


Best.


K. Frank

Ian Collins

unread,
Feb 19, 2017, 1:33:38 PM2/19/17
to
Use JSON to exchange data between your web application and the back end.
Once you do that, you can choose whatever you like for the back end code.

--
Ian
0 new messages