[Coco] The Coco's first webserver, written in Basic09
Aaron Wolfe
aawolfe at gmail.com
Wed Dec 30 10:34:48 EST 2009
On Wed, Dec 30, 2009 at 10:27 AM, George Ramsower
<georgeramsower at gmail.com> wrote:
> This made me laugh out loud!
> This server has processed 27 requests since it last crashed.
>
> I loved it!
>
> Perhaps, instead of generating the code, you could build the code into a file and send the file instead?
> Whucha think?
definitely! i wanted the initial run to work as quickly as possible
so serving out of code right now. sending files is absolutely going
to be added. it will be considerably slower, but for personal use
will work just fine.
86 requests and holding... :)
-Aaron
>
> Variables could be added as needed.... been there, done that.
>
> George
> ----- Original Message -----
> From: Aaron Wolfe
> To: CoCoList for Color Computer Enthusiasts
> Sent: Wednesday, December 30, 2009 9:02 AM
> Subject: [Coco] The Coco's first webserver, written in Basic09
>
>
> Hi folks,
>
> The Coco is now serving up web pages.. I guess it was only a matter of time :)
>
> http://home.spogbiper.com/
>
> Not much to look at, but all HTTP is processed and all HTML is
> generated by the Coco.
> All that drivewire is doing is passing raw data from TCP socket to the
> Coco over a DriveWire virtual channel.
>
> The source for the web server is below. I hope it serves as an
> example of how easy it is to use the new features in drivewire to
> write programs that talk to the outside world.
>
> It can easily be improved to do much more. I plan to have it serving
> up files and show directory listings for Coco disks soon. You'll be
> able to browse files on your Coco using a browser and fun things like
> that.
>
> As a side note, I added "weather" command to my test coco that will
> show you the weather for many cities or zip codes.
>
>
> Basic09 source for "httpd" (please don't laugh, its my first Basic09 program):
>
>
>
> PROCEDURE httpd
> DIM port_path:BYTE
> DIM port_name:STRING[4]
> DIM errnum,tmp:INTEGER
> DIM reqstr:STRING
> DIM reqid:BYTE
> TYPE servin = id:BYTE; control:BYTE; dat:STRING[128]
>
> DIM srv_in:servin
> DIM hits:INTEGER
>
> port_name="/U0"
> hits=0
>
> ON ERROR GOTO 100
> 10 OPEN #port_path,port_name:UPDATE
>
> PRINT "USING UTILITY PORT ";port_name
> GOTO 30
>
> 20 PRINT "TRY NEXT"
> tmp := PEEK(ADDR(port_name)+2)
> tmp := tmp + 1
> POKE ADDR(port_name) + 2, tmp
> GOTO 10
>
> 30 PRINT "MAIN LOOP"
> ON ERROR GOTO 200
>
> PRINT #port_path,"httpd"
> PRINT #port_path,"start"
>
> REPEAT
>
> REPEAT
> GET #port_path,srv_in
>
> IF LEFT$(srv_in.dat,3) = "GET" THEN
> reqstr = TRIM$(RIGHT$(srv_in.dat,124))
> reqid = srv_in.id
> ENDIF
>
> UNTIL (srv_in.control = 1) OR (srv_in.control = 0)
>
> hits = hits + 1
>
> IF srv_in.control = 1 THEN
> print "REQUEST",reqstr
>
> IF LEFT$(reqstr,2) = "/ " THEN
> PRINT #port_path,"HTTP/1.1 200 OK"
> PRINT #port_path,"Server: COCO OS9 DriveWire"
> PRINT #port_path,"Connection: close"
> PRINT #port_path,""
> PRINT #port_path,"<HTML>"
> PRINT #port_path,"<BODY BGCOLOR=#33FF33>"
> PRINT #port_path,"<P><CENTER><H1>coco!</h1><P>"
> PRINT #port_path,"<h4>This page is served by a Color Computer 3<BR>"
> PRINT #port_path,"running <A
> HREF=http://www.nitros9.org/>NitrOS-9</A>"
> PRINT #port_path,"and <A
> HREF=http://www.frontiernet.net/%7Emmarlette/Cloud-9/Software/DriveWire3.html>DriveWire</A>"
> PRINT #port_path," <P>For more information on this
> project, <A HREF=http://aaronwolfe.com/coco>click here</A><P>"
> PRINT #port_path,"This server has processed "
> PRINT #port_path,hits
> PRINT #port_path," requests since it last crashed.</H4>"
> PRINT #port_path,"</BODY>"
> PRINT #port_path,"</HTML>"
> PRINT #port_path,CHR$(0)
> ELSE
> GOSUB 1000
> ENDIF
>
> ENDIF
>
> UNTIL srv_in.control = 0
>
> CLOSE #port_path
> END
>
> 100 errnum := ERR
> IF errnum = 250 THEN
> PRINT "BUSY ON PORT ",port_name
> GOTO 20
> ELSE
> PRINT "ERROR ", errnum, " ON PORT ", port_name
> END
> ENDIF
>
>
> 200 errnum := ERR
> PRINT "ERROR ", errnum
> CLOSE #port_path
> END
>
> 1000 PRINT #port_path,""
> PRINT #port_path,CHR$(0)
>
> RETURN
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>
More information about the Coco
mailing list