[Info-vax] A light WEB server in C

Richard Maher maher_rj at hotspamnotmail.com
Sat Jan 9 17:36:55 EST 2010


Hi CY,

"Mark Daniel" <mark.daniel at wasd.vsm.com.au> wrote in message
news:00d22d3d$0$15564$c3e8da3 at news.astraweb.com...
> Jan-Erik Söderholm wrote:
> > CY wrote:
> >> On 9 Jan, 00:58, Steven Schweda <sms.antin... at gmail.com> wrote:
> >>>    I'm confused.  So, you've written the world's smallest Web
> >>> server, and now you want to write the world's smallest Web
> >>> browser?  Or what?
> >>
> >> No, a small server app that one can connect to and that accept a
> >> numeric input, my question was about accepting the input from the
> >> client
> >> and NO I didnt write the client, both IE and opera comes pre intealled
> >> on my phone
> >>
> >> //CY
> >
> > It wasn't clear why something like WASD wasn't possible.
> > That way you get all HTTP/CGI/whatever things running
> > out of the box and your "small server app" gets much easier
> > to write.
>
> If you really want to have a play from first principles then you need to
> understand basic TCP/IP programming (you seem to have your example
> listener code).
>
>    http://en.wikipedia.org/wiki/BSD_sockets
>
> The fundamental protocol of the Web
>
>    http://en.wikipedia.org/wiki/HTTP
>
> And overviews of a slew of related technologies
>
>    http://www.w3schools.com/
>
> Of course there are a myriad of of on-line and printed resources
> accumulated over the now nearly two decades of the existence of Web.
>
> Donate annually
>
>    http://wikimediafoundation.org/wiki/Support_Wikipedia/en
>
> I, and many I know, do (it's refreshing to see no ads, textual or
> otherwise).

Before we wrote our own, and blisteringly fast Applet Uploader (only handles
GETs) we used a Mickey Mouse DCL server that I think was written by Bojan
Nemec but the one I found here was, I beleive posted/improved by Mark
Daniel. (It's called MARK_HTTP.COM anyway :-)

Cheers Richard Maher

$!--------------------------------------------------------------------
$ server_user = f$edit(f$getjpi(0,"username"),"trim")
$ home_dir    = f$trnlnm("sys$login","lnm$job")
$ set default 'home_dir
$!
$ create http_server.com
$ deck
$!(seems noticably to improve performance)
$ set rms /buffer=255 /block=127 /network=127
$ open /read /write net sys$net
$ read net httpcmd /time=10 /error=end
$ method = f$element (0 , " " , httpcmd)
$ path = f$element (1 , " " , httpcmd)
$ show symbol /all
$!
$ if method .eqs. "GET"
$ then
$!   (used this filename reduction when fiddling, not always required)
$    count = 0
$    name_loop:
$       count = count + 1
$       filename = f$element (count, "/", path)
$       if filename .nes. "/" then goto name_loop
$    end_name_loop:
$    filename = f$element (count-1, "/", path)
$    if filename .eqs. "" then filename = "index.html"
$    filename = "t3$applets:" + filename
$!
$    if f$search(filename) .nes. ""
$    then
$       ctype = "application/octet-stream"
$       file_type = f$edit(f$parse(filename,,,"TYPE"),"upcase")
$       if file_type .eqs. ".HTML" then ctype="text/html"
$       if file_type .eqs. ".TXT" then ctype="text/plain"
$       if file_type .eqs. ".GIF" then ctype="image/gif"
$       if file_type .eqs. ".JPG" then ctype="image/jpeg"
$       if file_type .eqs. ".PNG" then ctype="image/png"
$       if file_type .eqs. ".ZIP" then ctype="application/zip"
$       if file_type .eqs. ".JAR" then ctype="application/java-archive"
$       if file_type .eqs. ".CONF" then ctype="text/plain"
$!
$       len = f$file(filename,"FFB")
$       if len .eq. 0 then len = len + 512
$       len = (f$file(filename , "EOF") - 1) * 512 + len
$       rfm = f$file(filename,"rfm")
$!
$       write net f$fao("HTTP/1.0 200 OK!/")
$       write net f$fao("Content-type: ''ctype'!/")
$       write net f$fao("Connection: close!/")
$       write net f$fao("Pragma: nocache!/")
$       set noon
$       if rfm .eqs. "VAR" .or. rfm .eqs. "VFC"
$       then
$!         (assume it needs carriage-control)
$          write net f$fao("!/")
$          open /read /share=read file 'filename'
$          read_loop:
$             read /end=end_read_loop file record
$             write net f$fao("!AS!/", record)
$             goto read_loop
$          end_read_loop:
$          close file
$       else
$!         (assume it's all contained in the bag-o'-bytes)
$          write net f$fao("Content-Length: ''len'!/")
$          write net f$fao("!/")
$          exchange copy /log 'filename' net -
                          /transfer=block /carriage=none
$       endif
$       exit
$    endif
$    write net f$fao("HTTP/1.0 404 not found!/!/")
$    exit
$ endif
$ end:
$ write net f$fao("HTTP/1.0 501 not implemented!/!/")
$ exit
$ eod
$!
$ set noon
$ define/user sys$output nl:
$ define/user sys$error  nl:
$ ucx
disable service http_dcl
set noservice http_dcl /noconfirm
$ set on
$!
$!(a /LIMIT well above 1 is important for any compound HTML document!)
$ ucx set service http_dcl -
           /user_name = 'server_user' -
           /limit = 10 -
           /port = 80 -
           /protocol = tcp -
           /process = http_dcl -
           /file = 'home_dir'http_server
$ ucx enable service http_dcl
$!
$ exit
$!--------------------------------------------------------------------





More information about the Info-vax mailing list