tags:

views:

74

answers:

2

I would like to create a very bare-bones web server in C++ which only needs to respond to XMLHttpRequests. The idea to have an Apache server serving webpages which directs the XMLHttpRequests to an existing application so that the app can provide monitoring data to users. I have a hacky implementation working now where the existing app writes over an XML file on disk, but I'm afraid this is super inefficient, as the data changes at ~30Hz. I've never done any port programming, but I'm willing to learn. Does anyone have any places to start looking? An existing library would be great, but I could also deal with a straightforward explanation of the necessary protocol.

Thanks! --Boatzart

+1  A: 

You want to write a module for nginx. IMO it pretty much has the best extension design from all the web-servers I have written code for. There are two well written and extensive guides on how to extend nginx.

and please --- do not write data as XML -- use berkeley DB (not sqlite3 as it was not designed for concurrent access) or a proper database back-end.

Hassan Syed
Sounds promising, but I already have Apache running, and I would like to avoid setting up a whole other web server - I would prefer my solution to be as lightweight and unobtrusive as possible. Would writing a thread in my existing C++ application which opens a port, listens only for XMLHttpRequests, and responds to only those with 4 numbers from memory really be so difficult?Also, I'm not actually using XML as a backend, I think you may be misunderstanding. The XML is just an easy format to send to a webpage. All the data is just runtime statistics from my application - no database needed.
Boatzart
There are a lot of subtleties with the HTTP protocol that you must address with any implementation -- it is therefore prudent to have the protocol encapsulated by someone else. If you really must stick with apache than you can just write an apache_mod.
Hassan Syed
A: 

I advice you to use some normal web server like Apache/light httpd and a normal CGI interface.

Coding your webserver would be a painfull process, make some CGI in C is not really easy but at least well documented and would be more efficient.

You can also maybe do some sort of daemon in python or some other language.

On other possibility is to make a normal network daemon in C, using your own protocol and make your web front-end talk to this daemon.

You can also use DBM like memcached to have some fast storage.

RageZ
For those who feels to downvote can they give a comment at least ?
RageZ