Forgot your password?
typodupeerror
Programming Links The Internet IT Technology

A TCP/IP Stack and Web Server In BASIC 251

A writes "Back in the day, a BASIC interpreter was standard on every home computer system and everyone had to know at least a little BASIC to be able to use their computer. But who would have thought that you could write some serious networking code in BASIC over 20 years later? Just a few days ago, Lee Davison released the BASIC source code for his 6502-based Ethernet web server. The web server runs under his EhBASIC interpreter on the 1 MHz 6502 CPU and is able to blast out web pages at an amazing speed of 20-35 seconds per page!" Sure, it's not really practical, but I give it cool points.
This discussion has been archived. No new comments can be posted.

A TCP/IP Stack and Web Server In BASIC

Comments Filter:
  • by dioscaido ( 541037 ) on Saturday August 16, 2003 @09:44AM (#6711978)
    Can the code really be called BASIC? It looks more like tons of in-line assembly code, wrapped in a few ifs and loops.
  • by Ed Avis ( 5917 ) <ed@membled.com> on Saturday August 16, 2003 @09:44AM (#6711981) Homepage
    Since the code seems to be mostly direct memory access, CALL, and USR, wouldn't it have made more sense simply to write it in assembly language?

    You can use a BASIC dialect that has a built-in assembler and so still get suitably old-school source code.
  • by taybin ( 622573 ) <taybinNO@SPAMtaybin.com> on Saturday August 16, 2003 @09:51AM (#6712009) Homepage
    Well, that's BASIC for you. It doesn't have very good library support. As far as I know, it didn't have any library support if it wasn't built into the interpretor.
  • Next... (Score:2, Interesting)

    by ihummel ( 154369 ) <<ihummel> <at> <gmail.com>> on Saturday August 16, 2003 @09:52AM (#6712014)
    someone will come up with a shell script webserver.
  • interesting (Score:1, Interesting)

    by Anonymous Coward on Saturday August 16, 2003 @09:53AM (#6712019)
    I'd like to see how this benchmarks on a 1Ghz modern processor or better. ANyone planning on setting this up and benchmarking it BEFORE posting it on slashdot?
  • by DoctorPepper ( 92269 ) on Saturday August 16, 2003 @09:57AM (#6712026)
    Yes, actually. Look in your ports collection. A real quick grep turned this up:

    $ ls | grep basic
    bwbasic/
    gnomebasic/
    pbasic/
    wxbasic/
    y abasic/
  • Re:Next... (Score:3, Interesting)

    by FnordPerfect ( 240722 ) on Saturday August 16, 2003 @10:06AM (#6712065) Homepage
    done already. This one is in bash...

    http://linux.umbc.edu/~mabzug1/bash-httpd.html
  • by DrSkwid ( 118965 ) on Saturday August 16, 2003 @10:30AM (#6712143) Journal
    inline-assembler
    definable functions
    re-entrant procedures

    http://www.bbcbasic.com/

    Sophie Wilson did a great job and did anyone at school in the UK who was interested in computing the biggest favour of all - she gave us the gift of learning structured programming from day 0

  • by yellowstone ( 62484 ) on Saturday August 16, 2003 @10:33AM (#6712170) Homepage Journal
    Can the code really be called BASIC?
    Old-skool BASIC was really heinous:
    • Variable names limited to two characters
    • Only data types are integers and strings
    • No structured data types, only (fixed size) arrays
    • No names in control flow, just GOTO 100 and GOSUB 9000. No parameters for subroutines.
    • Plus, it was typically interpreted, for extra slowness at run time.
    It looks more like tons of in-line assembly code
    It's worse than assembly. At least in assembly, you can have longer identifiers, and use them in data and control flow statements.
  • Re:Damn (Score:2, Interesting)

    by Dogtanian ( 588974 ) on Saturday August 16, 2003 @10:35AM (#6712178) Homepage
    Why can't everyone just agree that BASIC is dead, should stay dead and preferably staked through the heart? I personally can't see any use at all for BASIC.

    I'd probably agree with you on that one.... but it's interesting to note that many of the commonly-criticized features of Basic were the result of memory-kludges and featuritis, that the original designers of Basic did not approve of at all (according to their book 'Back to Basic').

    Unfortunately, I don't have the book to hand to check out the details, but here's a link [amazon.com] to it anyway.
  • Re:Next... (Score:5, Interesting)

    by DrSkwid ( 118965 ) on Saturday August 16, 2003 @11:34AM (#6712408) Journal
    no problem

    %tcpserver 127.0.0.1 80 /home/www/webserver.rc

    --- webserver.rc ---

    #!/usr/local/bin/rc

    root = '/home/www/document_root'

    fn echo_response {
    echo 'HTTP/1.1 ' ^$response
    }

    fn echo_date {
    echo -n 'Date: '
    /bin/date
    }

    fn echo_content_type {
    echo -n 'Content-Type: '
    /usr/bin/file -m /usr/share/misc/magic.mime $path | /usr/bin/awk ' { print $2 } '
    }

    fn echo_content_length {
    echo -n 'Content-Length: '
    /bin/cat $path | /usr/bin/wc -c | /usr/bin/tr -d ' '
    }

    fn respond {
    echo_response
    echo_date
    echo 'Server: rc shell'
    echo_content_length
    echo_content_type
    echo 'Connection: close'
    echo
    /bin/cat $path
    }

    ifs = '
    '

    for (request in `{echo -n}) {
    url = $request(2)
    file = `{echo $url | sed 's/http:\/\/[^\/]*//' | tr -d \012}

    path = $root ^$file
    echo $path
    if (/bin/test -e $path) {
    response = '200'
    } else {
    response = '404'
    path = $root ^'/404.html'
    }

    respond
    }

  • oops, wrong version (Score:5, Interesting)

    by DrSkwid ( 118965 ) on Saturday August 16, 2003 @11:44AM (#6712452) Journal
    unlike the others I wrote mine from scratch in response to the post

    sadly I posted a slightly wrong version

    here's the one that works

    http://www.proweb.co.uk/~matt/rc/webserver.rc

    it's only a toy, of course.

    http://server/../../../../../../etc/passwd

    will get you the passwd file
  • by sverrehu ( 22545 ) on Saturday August 16, 2003 @11:54AM (#6712494) Homepage
    ... for stuff like this. The annual Totally worthless, 100% hack value [catb.org], too-much-geek-time-to-spare prize. And the 6502 BASIC TCP/IP stack-based web server should be the first winner.
  • clarification (Score:3, Interesting)

    by MegaFur ( 79453 ) <wyrd0@komy.z[ ]com ['zn.' in gap]> on Saturday August 16, 2003 @12:24PM (#6712635) Journal

    It's worth mentioning that, for the C64/128 at least, you could actually have variable names longer than two characters but only the first two characters would be recognized. All the rest were ignored. By way of example, here's a made up code sample. Since my C128 is currently in the closet, I can't guarentee this example's accuracy. Some other pedant may wish to.

    Example
    10 LET FROGS = 16
    20 LET FRAGGLE = 12
    30 LET FRANCE = FROLLIC * FROBNITZ
    40 PRINT FROGS

    Output: 144

  • PowerBASIC (Score:2, Interesting)

    by arashiakari ( 633150 ) on Saturday August 16, 2003 @12:43PM (#6712740) Homepage
    I use PowerBASIC [powerbasic.com] every day. It is the best Win32 (soon to be cross-platform) compiler I have ever seen. And yes, it has TCP/IP stack. :) Being a 32-bit compiler it using OS APIs to create TCP/IP connections.

    I use it in conjunction with .NET and ANSI C. Check out their company history [powerbasic.com] for some background then take a look at the delicious capabilities of their Windows [powerbasic.com] and Console [powerbasic.com] compilers.

    They also have a kick-ass DOS Compiler [powerbasic.com] that has put dinner on my table for years. As we know, many people are still using DOS and DOS-mode apps every day.

    When looking at PowerBASIC you have to get rid of any preconcieved notions of BASIC or how it has been implimented in the past. PowerBASIC is a dream to use, has a huge community, and compilers smaller and faster than most ANSI C programs I've seen. Also, check out their partial client list [powerbasic.com] - you'll be in good company.

    No, I do not work for them. I am a loyal customer and a geek that loves cool stuff. PB delivers.

  • BASIC Webserver (Score:2, Interesting)

    by gmcclel ( 43020 ) * on Saturday August 16, 2003 @01:42PM (#6713012) Homepage
    There is a production webserver written in ProvideX [pvx.com] (a Business Basic dialect). It's been around for 4-5 years. I use it for my Kevin & Kell [herdthinners.com] website. The main index.phtml page looks like:
    master=hfn
    open (master)"file"
    first_strip$=kef(master)
    today=jul(0,0,0)
    last_strip$=dte(today:"%Yl%Mz%Dz")
    if len(current$)=0 or current$>dte(today:"%Yl%Mz%Dz") {
    current$=dte(today:"%Yl%Mz%Dz")
    }
    get_desc:
    read (master,key=current$,dom=*next)*,kkdesc$; goto GOT_DATE
    [...]
  • by Nexzus ( 673421 ) on Saturday August 16, 2003 @01:53PM (#6713064)
    Quick question, if you don't mind.

    Is that why all loops in any language in any source code seem to use i and j?

    I know I do it, and I know I (sh|c)ould use something like $counter, but I've seen i and j so many times in code snippets, it's become almost second nature.
  • by Anonymous Coward on Saturday August 16, 2003 @08:05PM (#6714542)
    I'm pretty sure that all variants had floating point data types as well.

    I'm going to take a wild guess and assume that you've never used "Integer BASIC" on the Apple ][. No, I don't mean the Apple][+ or the Apple ][e or the special Wozniak-autographed Apple ][gs. I mean the Apple ][ that came with 16 kB of RAM and required you load your interpreter into a "language card". And required you to buy an "80-column card" if you didn't like working in 40 columns of text.

    But you could DIM them dynamically using a variable.

    Again, not all versions of BASIC had this. The TI99-4/A BASIC dialect did not allow you to do this. The part inside the DIM statement had to be a constant. I know; I tried it and was disappointed when I realized AppleSoft BASIC allowed it but TI BASIC didn't.

Let's organize this thing and take all the fun out of it.

Working...