C++ Apache HTTP server?

Started by
11 comments, last by Antheus 15 years, 8 months ago
It can be added that writing Apache modules is really nice and easy, much thanks to the frameworks involved. If you download the Apache source code, you'll probably find samples named mod_hello or mod_cpphello, which IIRC outputs data directly to the client.
Advertisement
I'm still not quite sure what your web server part is supposed to do.

Do you already have a server, and you want to connect to it to get statistics and set management information? Then turning your server into an Apache module is not the right answer. Hack your own in 200 lines and call it good.

Do you want to set up a server for a web-page game? If so, I suggest using Apache, or some other web server, and writing the game itself in Flash or Java.

Do you want to write a client/server application, and use HTTP for transport for network communications? If so, I suggest using an application server, or Java servlet server, such as Tomcat or one of the J2EE servers.
enum Bool { True, False, FileNotFound };
hplus, I'm looking into a way where I can replace PHP. I want to do a few tests to see if using a native language will make much difference, I'm also looking into a way where I can use simply put up a game server which allows http connections as well (for configuring in-game things). Well...I don't really have a goal, I simply want to get known with HTTP server building...using C++ to send HTML to the client...:)

I think Apache would be nice, I've also downloaded a simply Win32 socket HTTP server class, it works very nice and uses forms and authentication etc. But it's windows only, while Apache is cross platform.

CGI, looked into that, could not get it to work when I quickly tried it :S, I'll see how building a module goes :).

Thanks!
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Quote:Original post by Decrius
hplus, I'm looking into a way where I can replace PHP.


A HTTP server is passive, when it receives an HTTP request, it generates some response. While various push technologies have been developed, today's AJAX uses same concept. Even though it appears async, server still merely responds to queries.

As such, almost all application frameworks operate on exactly the same concept. You implement some function, which receives a Request object. Your code then produces a Response, and optionally writes something to the stream.

PHP does just that. The URL identifies the script, which is then executed, and resulting text is sent to client.

Quote:which allows http connections as well (for configuring in-game things).


Here you will run into problems if you try to do it yourself. While various performance improvements were added to HTTP (re-use of connections instead of one connection per request), HTTP is still session-less. As such, various techniques need to be used to keep track of which HTTP connection belongs to which client. After taking into consideration that browsers are free to open multiple connections, that they may time-out or expire, and that there's several options of how to track users (cookies, URL-encoded), as well as possible browser incompatibilities, this really is a task that's by far best suited for any given Web App framework.

Quote:Well...I don't really have a goal, I simply want to get known with HTTP server building...using C++ to send HTML to the client...:)


1) Write a TCP/IP server than can handle multiple clients
2) Read the HTTP documentation on the requests (GET, later POST), the URL and MIME encodings
3) Static HTTP server then accepts a connection, and reads the request fully.
4) Extract the URL from request, and map it to file system (www.example.com/foo/bar.txt would map to /home/myself/wwwroot/foo/bar.txt)
5) On success, load the file from disk, send it to client (may need proper MIME encoding) formatted as response
6) On failure, see the documentation on what to send

Quote:I think Apache would be nice, I've also downloaded a simply Win32 socket HTTP server class, it works very nice and uses forms and authentication etc. But it's windows only, while Apache is cross platform.


If you haven't yet, install apache, set up Wiki or some other web app, and mess around with that.

This topic is closed to new replies.

Advertisement