24
Sep
G3DServer C++ Web Framework / Server
By Joseph Montanez
0 Comment

« Download 0.0.4a C++ Web Framework / Server
« Benchmark & Code Revision

I am still a bit new to c++, and the make platform so hopefully this will go okay.

Compile the source

unzip webserver-0.0.4.zip
cd webserver
make
cd ../website
make
website demo requires sqlite3 devel libs

Run The Demo

./dist/Debug/GNU-Linux-x86/website
Goto your browser http://localhost:8181/ and the demo should run!

Make it yours

The file "website/main.cpp" is the file that pulls my code together. So you can use that as a reference to making new controllers adding to the url map.

Where is the API or Docs?

There are none, i really cant see someone using this right now, its not tested in a production environment and just a proof of concept.

Complete Example

#include "WebController.h"
#include "WebServer.h"
#include "ServerSocket.h"
#include "SocketException.h"
#include <string>
#include <iostream>
#include <map>

class HomeController : public WebController {
public:
    void get() {
        this->session->set("foo", "bar");
        this->response->body.append("\
            <html>\
            <head>\
                    <title>Before</title>\
            </head>\
            <body>\
            " + this->request->get("asdfasdf") + "\
            <form action=\"\" method=\"post\">\
            <input type=\"hidden\" name=\"asdfasdf\" value=\"dsfasdfasdf\" />\
            <input type=\"submit\" name=\"submit\" value=\"Push\" />\
            </form>\
			<br /><a href=\"/after\">After</a>\
            </body>\
            </html>\
        ");
    }
};
class AfterController : public WebController {
public:
    void get() {
        this->response->body.append("\
            <html>\
            <head>\
                    <title>After</title>\
            </head>\
            <body>\
            " + this->session->get("foo") + "\
			<br /><a href=\"/\">Before</a>\
            </body>\
            </html>\
        ");
    }
};

int main(int argc, char* argv[]) {
    WebServer* server = new WebServer();

    server->port = 8181;
    server->addController("/", new HomeController());
    server->addController("/after", new AfterController());

    server->run();
    delete server;
    return 0;
}

« Back to my notebook
< Previous Note
Comment Pages: 1


esign