[Coco] The Coco's first webserver, written in Basic09

Gene Heskett gene.heskett at verizon.net
Wed Dec 30 10:33:19 EST 2009


On Wednesday 30 December 2009, Aaron Wolfe wrote:
>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.ht
>ml>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
>

I'm going to have to turn the hear way up, its getting positively Kewl in 
here.  And having done a few things in B09, that looks pretty good to me.
Lots of room for expansion yet.

Congratulations are in order, and these are exciting times for coco fans.

-- 
Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)

         EARTH          
     smog  |   bricks  
 AIR  --  mud  --  FIRE
soda water |   tequila 
         WATER        



More information about the Coco mailing list