Tntnet – a small C++ based web server

Being a fan of C++ and having a new Embedded Linux project in the pipeline, a colleague recently put my interest onto the small C++ based web server Tntnet. Tntnet essentially is a framework that allows to generate rich dynamic web applications using C++ and a model-view-controller approach – just like Rails (Ruby) or Django (Python). For this task Tntnet comes with a variety of tools: a sort of “meta compiler” that generates pure C++ code out of so-called “ecpp” files (which are a mixture of HTML and C++ code), the standalone web server executable and the Cxxtools C++ library that brings stuff like JSON / XML RPC, logging capabilities and much much more. Before hacking any code developers have two options to deploy a web application: either compiling the web stuff as shared library, which in turn can be loaded as a module by the standalone Tntnet executable, or compiling everything into a single application, which then serves as the web server providing the content. The latter case contains of a simple main() entry function in which the server is set up and configured. It may look like this:

The above code is essentially copied from the Tntnet Quick Start Guide.

Writing CMake scripts to search and use these tools and libraries merely took a few minutes and an hour later (reading my way through the documentation and Howtos on the official website) my first web application (a simple CRC32 Checksum calculator) compiled successfully. Due to its C++ nature the application has a really small footprint (~230 KB), serves http requests amazingly fast and hence seems like the ideal solution for our new project.

Sorry that I don’t have any more examples for now, but I will update you later with some stats (comparing Apache2 and Tntnet using the Apache2 Benchmark suite) and more code. So long and keep on hacking.