C++ Apache HTTP server?

Started by
11 comments, last by Antheus 15 years, 8 months ago
Hi everyone, I'm trying to build a HTTP server using libCURL. I find the tutorials quite lacking (or I haven't found the tutorial pages...!), so I was wondering if anyone had a very quick example code which would return text if someone accesses the server (using http://localhost for example). Or could anyone link me to any resource site explaining the use of cURL and how one could build a server using it. I've compiled it successfully, and a download script (client-side) which I found on these forums works excellent... Thanks! EDIT: or would there be a better library for this? [Edited by - Decrius on August 4, 2008 1:05:17 PM]
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Advertisement
libCURL is client-side, not server-side. It is not suitable for implementing an HTTP server.
Quote:EDIT: or would there be a better library for this?
Try Apache.
A HTTP server is TCP/IP connection handler. If you can write TCP/IP server, you can write HTTP server.

HTTP in itself is documented, and very mundane. What is of interest to you is the document encoding, and request/response generation.

A trivial implementation of this functionality can be found as boost asio example.

You could also look at libcURL, to see how it handles the request/response, and then reverse that.

But main problem with lack of tutorials really is in the fact that the process is incredibly boring, and, if it is intended to be fully HTTP compliant, fairly extensive.
Aye, had a feeling for that.

Would like to use boost.asio, looks like it has some nice examples :)
Thanks!
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Quote:Original post by Decrius
Would like to use boost.asio, looks like it has some nice examples :)
Thanks!

Seriously, use Apache unless you have a damn good reason not to. Writing a barebones HTTP server from scratch is simple; writing a good one is very hard.
Quote:Original post by Sneftel
Quote:Original post by Decrius
Would like to use boost.asio, looks like it has some nice examples :)
Thanks!

Seriously, use Apache unless you have a damn good reason not to. Writing a barebones HTTP server from scratch is simple; writing a good one is very hard.


True, but I saw some HTTP examples over there, but they give very weird compiling errors.

How would I use Apache? Is it a library, or should I run it and connect to it using C/C++? I'm really looking for a small server...

Or could I somehow write an extension to Apache? How does PHP do this? *confused*
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Quote:Original post by Sneftel
Try Apache.
This may sound like a stupid advice at first, but seriously... do it! It's the absolutely best advice.
Apache is something that "just works", and it works really well. There may be one or the other solution that performs a bit better in some special cases, but so what. Apache works, fullstop.

On what is considered low-low-end hardware today, Apache will physically saturate the ethernet cable with ease, unless you do a dozen database queries and excessive scripting for every page hit. And if you do that, other solutions won't be much faster either.

To use Apache, you install it on your server, tweak a few configuration settings, and launch the server process. That's it.
If you need something else than static pages, you can write CGI/fastCGI apps, or you could just use PHP or some other scripting language. PHP is surprisingly fast, more than one would expect (especially when using an accelerator/cache).
Quote:Original post by samoth
Quote:Original post by Sneftel
Try Apache.
This may sound like a stupid advice at first, but seriously... do it! It's the absolutely best advice.
Apache is something that "just works", and it works really well. There may be one or the other solution that performs a bit better in some special cases, but so what. Apache works, fullstop.

On what is considered low-low-end hardware today, Apache will physically saturate the ethernet cable with ease, unless you do a dozen database queries and excessive scripting for every page hit. And if you do that, other solutions won't be much faster either.

To use Apache, you install it on your server, tweak a few configuration settings, and launch the server process. That's it.
If you need something else than static pages, you can write CGI/fastCGI apps, or you could just use PHP or some other scripting language. PHP is surprisingly fast, more than one would expect (especially when using an accelerator/cache).


Thanks for the advice. I'm willing to use Apache, but I wonder how I ever could use C to send and receive data from a client. I simply want to 'replace' PHP in this case, I should be able send HTML and receive GET and POST values. Apache would be THE solution, since I can use Mod Rewrite then aswell.

So, does anyone have an example of it? Or a resources site which describes how one can connect to apache?

[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
What you are looking for is CGI or fastCGI. It will let you use just about any language out there to do web programming. try googling cgi c++
Quote:Original post by Decrius
Quote:Original post by Sneftel
Quote:Original post by Decrius
Would like to use boost.asio, looks like it has some nice examples :)
Thanks!

Seriously, use Apache unless you have a damn good reason not to. Writing a barebones HTTP server from scratch is simple; writing a good one is very hard.


True, but I saw some HTTP examples over there, but they give very weird compiling errors.

How would I use Apache? Is it a library, or should I run it and connect to it using C/C++? I'm really looking for a small server...

Or could I somehow write an extension to Apache? How does PHP do this? *confused*
The latter. As for how to do it, there's a few ways. The simplest is to make a CGI program, referred to by the Apache configuration; Apache receives a request, passes it along to your program, and your program responds with whatever data you want. It really is as simple as that. Since CGI programs are just regular programs, you can write them in whatever language you like.

For greater efficiency and control over the server, you can write an Apache module which is invoked directly. See the Apache documentation for details. If you start out with a CGI program, it's straightforward to transition to a module later if needed, so don't bother with the module stuff right out of the gate.

This topic is closed to new replies.

Advertisement