August 18th, 2003, 05:34 AM
Where do I start with simple (?) webserver program?
I want to write (preferably using C) a webserver program with the basic purpose of responding to POST requests and passing these to CGI programs. I simply want to avoid the hassle of setting up a full commercial webserver. Ideally it should be cross platform (PC & Mac) but I want to start off on PC. I've seen several sources of info including some simple apps for serving web pages and wonder if and how these would need to be extended to include support for CGI.
Without allowing this to digress too much I'd also like to know if there's a simpler/better way of achieving what I want. That is a service that can receive communication via a URL from popular authoring tools such as Flash and Director and then write info to file/database. It needs to be simple to install and run on a LAN and possibly on web and standalone computer too. It also needs to be freely distributable.
Any advice please?
August 18th, 2003, 08:19 AM
Just install linux/unix and apache, and use perl/php.
Why re-invent the wheel?
August 18th, 2003, 08:34 AM
Not exactly the response I was after - thanks anyway.
Perhaps I wasn't clear enough ... I want this to run on a system without having to install a full webserver.
August 18th, 2003, 08:40 AM
Suit yourself.. your going to spend much more time writing a webserver than you will simply using apache.
August 18th, 2003, 08:48 AM
May we know the reasons why you don't want to run a webserver? I mean, if it's for learning reasons ok, if not, why? Be sure that apache (or whatever) guys know much more than you, me and most of us.
August 18th, 2003, 10:11 AM
August 18th, 2003, 01:05 PM
If you really want to write your own webserver, here's one that I wrote in python. It should be portable across Windows, *Nix and Mac as well.
Now, when running this code, make a cgi-bin/ directory under the directory where the python program is and put your CGI scripts there. This is because the CGIHTTPRequestHandler assumes CGI scripts to reside under /cgi-bin or /htbin by default and will only execute CGI scripts from there. If you want to use different dirs for CGI scripts, declare your own class that inherits from CGIHTTPRequestHandler and set the value of cgi-directories appropriately. See http://www.python.org/doc/current/li...TTPServer.html for details.
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
serveraddr = ('',80)
webserver = HTTPServer(serveraddr, CGIHTTPRequestHandler)
Now, put an HTML page something like this
Now you're all set :)
<form name="foobar" method="POST" action="http://192.168.1.16/cgi-bin/foo.cgi">
<input type="submit" value="submit">
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
August 19th, 2003, 10:16 AM
Thanks for the replies.
Python's certainly interesting. I've spent the morning downloading and playing with that.
I quite agree that Apache is a route to take if I just want to run a webserver. Or even IIS on Windows etc. I'm way out of that league. However I want to see if it's feasible to provide just one aspect of that - CGI Request handling - as a readily distributable and easily installable program. Programs that need to communicate with a database of some sort would then have a neat little 'webserver' to allow them to call CGI scripts to do that stuff and without the need for users to install a full webserver. That's the idea. And of course I'll learn useful skills.
The links are helpful and if anyone's done anything similar in C I'd still like to hear.