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

Tim Fadden t.fadden at cox.net
Wed Dec 30 11:01:16 EST 2009


Absolutely fabulous!

Sorry, but I think it was me who crashed it. :-(  Trying to get scred 
working.  ftp now switches to bin OK.
The file size was correct. did a scred -z=/x1/sys/termset -t=ansi
then got a #236 - Bad Module header.  Are you running 6809, or 6309?.  
Or bin transfers are getting munged.
I will stop messing around and keep your website up!  :-)

Tim Fadden


On 12/30/2009 8:02 AM, 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.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
>
>
>    




More information about the Coco mailing list