KISSCPP
a C++ library for rapid application development
|
Below, is the main.cpp for the kc_echo application. It serves as a basic demonstration of the power we have available to us, through KISSCPP.
It is a typical example of a main.cpp file, if you end up with a main.cpp file, that has more in it, you either have some very specific requirements or you aren't using the library as intended.
Examine the code above for a while, I hope it's clear that kc_echo is a class name, and that it's being instantiated within the try block of our main function. Immideately after, the run method of that object is then executed.
Now consider the kc_echo class:
That's it, that is all you need in order to have a basic server set up. Now consider the implimentation of that class:
That's it, all we need to do now, is implement the "echo" request handler. I follow a simple convention with handlers. I name the source files handler_ followed by the texctual id of the handler. i.e. With this example we'll have handler_echo.cpp and handler_echo.hpp. This serves to easily identify handlers from source file names.
Here is the EchoHandler class:
And now the last file you need for a complete kisscpp application.
Remarkably, this is the part I consider the most difficult to understand. Yet it also happens to be the portion that has the least going on.