[Coco] The Coco's first webserver, written in Basic09
aawolfe at gmail.com
Wed Dec 30 10:02:19 EST 2009
The Coco is now serving up web pages.. I guess it was only a matter of time :)
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
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):
TYPE servin = id:BYTE; control:BYTE; dat:STRING
ON ERROR GOTO 100
10 OPEN #port_path,port_name:UPDATE
PRINT "USING UTILITY PORT ";port_name
20 PRINT "TRY NEXT"
tmp := PEEK(ADDR(port_name)+2)
tmp := tmp + 1
POKE ADDR(port_name) + 2, tmp
30 PRINT "MAIN LOOP"
ON ERROR GOTO 200
IF LEFT$(srv_in.dat,3) = "GET" THEN
reqstr = TRIM$(RIGHT$(srv_in.dat,124))
reqid = srv_in.id
UNTIL (srv_in.control = 1) OR (srv_in.control = 0)
hits = hits + 1
IF srv_in.control = 1 THEN
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,"<BODY BGCOLOR=#33FF33>"
PRINT #port_path,"<h4>This page is served by a Color Computer 3<BR>"
PRINT #port_path,"running <A
PRINT #port_path,"and <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," requests since it last crashed.</H4>"
UNTIL srv_in.control = 0
100 errnum := ERR
IF errnum = 250 THEN
PRINT "BUSY ON PORT ",port_name
PRINT "ERROR ", errnum, " ON PORT ", port_name
200 errnum := ERR
PRINT "ERROR ", errnum
1000 PRINT #port_path,""
More information about the Coco