#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    7
    Rep Power
    0

    Where do I start with simple (?) webserver program?


    Hi,

    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?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    New Zealand
    Posts
    28
    Rep Power
    0
    Just install linux/unix and apache, and use perl/php.

    Why re-invent the wheel?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    7
    Rep Power
    0
    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.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    New Zealand
    Posts
    28
    Rep Power
    0
    Suit yourself.. your going to spend much more time writing a webserver than you will simply using apache.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    BCN
    Posts
    84
    Rep Power
    13
    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.
  10. #6
  11. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    http://www.winsockvb.com
    http://lib.daemon.am/Books/TCP_IP/
    (Might be useful, some other links I had were 404)
  12. #7
  13. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    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.
    Code:
    !/usr/local/bin/python
    from BaseHTTPServer import HTTPServer
    from CGIHTTPServer import CGIHTTPRequestHandler
    
    serveraddr = ('',80)
    webserver = HTTPServer(serveraddr, CGIHTTPRequestHandler)
    webserver.serve_forever()
    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.

    Now, put an HTML page something like this
    Code:
    <html>
      <head><title>Post Test</title></head>
      <body>
        <h1>hello world</h1>
          <form name="foobar" method="POST"  action="http://192.168.1.16/cgi-bin/foo.cgi">
          <input type="submit" value="submit">
          </form>
      </body>
    </html>
    Now you're all set :)
    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
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    7
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo