Slashdot Mirror


A TCP/IP Stack and Web Server In BASIC

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.

18 of 251 comments (clear)

  1. Looks more like assembler to me... by dioscaido · · Score: 5, Interesting

    Can the code really be called BASIC? It looks more like tons of in-line assembly code, wrapped in a few ifs and loops.

    1. Re:Looks more like assembler to me... by taybin · · Score: 2, Interesting

      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.

    2. Re:Looks more like assembler to me... by yellowstone · · Score: 4, Interesting
      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.
      --
      150 Opening BINARY mode data connection for slashdot.sig (129323052 bytes).
    3. Re:Looks more like assembler to me... by Nexzus · · Score: 2, Interesting

      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.

      --
      Karma: Can only be portioned out by the Cosmos.
    4. Re:Looks more like assembler to me... by Anonymous Coward · · Score: 1, Interesting
      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.

  2. Re:To quote Zahpod Beeblebrox... by Ed+Avis · · Score: 1, Interesting

    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.

    --
    -- Ed Avis ed@membled.com
  3. Next... by ihummel · · Score: 2, Interesting

    someone will come up with a shell script webserver.

    1. Re:Next... by FnordPerfect · · Score: 3, Interesting

      done already. This one is in bash...

      http://linux.umbc.edu/~mabzug1/bash-httpd.html

    2. Re:Next... by DrSkwid · · Score: 4, Interesting

      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
      }

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
  4. interesting by Anonymous Coward · · Score: 1, Interesting

    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?

  5. Re:WOW! And they said.. by DoctorPepper · · Score: 2, Interesting

    Yes, actually. Look in your ports collection. A real quick grep turned this up:

    $ ls | grep basic
    bwbasic/
    gnomebasic/
    pbasic/
    wxbasic/
    y abasic/

    --

    No matter where you go... there you are.
  6. BBC Basic was like that by DrSkwid · · Score: 4, Interesting

    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

    --
    There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
  7. Re:Damn by Dogtanian · · Score: 2, Interesting

    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 to it anyway.

    --
    "Slashdot - News and Chat Sites Deviant". (Click "homepage" link above for details).
  8. oops, wrong version by DrSkwid · · Score: 4, Interesting

    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

    --
    There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
  9. There should be a prize... by sverrehu · · Score: 2, Interesting

    ... for stuff like this. The annual Totally worthless, 100% hack value, too-much-geek-time-to-spare prize. And the 6502 BASIC TCP/IP stack-based web server should be the first winner.

  10. clarification by MegaFur · · Score: 2, Interesting

    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

    --
    Furry cows moo and decompress.
  11. PowerBASIC by arashiakari · · Score: 2, Interesting
    I use PowerBASIC 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 for some background then take a look at the delicious capabilities of their Windows and Console compilers.

    They also have a kick-ass DOS Compiler 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 - 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.

  12. BASIC Webserver by gmcclel · · Score: 2, Interesting
    There is a production webserver written in ProvideX (a Business Basic dialect). It's been around for 4-5 years. I use it for my Kevin & Kell 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
    [...]
    --
    --- Gary McClellan