Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

A TCP/IP Stack and Web Server In BASIC

Posted by CowboyNeal on Sat Aug 16, 2003 08:31 AM
from the rebirth-of-the-line-editor dept.
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.
+ -
story
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • If you want to slashdot it, the IP address is visible in some of the screen shots. It's 169.254.226.132, but I'm not cruel enough to actually turn that into a hyperlink. :-)
  • At 20+ secs per page - immediately?

    (I know the article isn't on the EhBASIC webserver - I was talking about any page served up by the webserver alone.)
  • ten out of ten for style, but minus several million for good thinking.

    I actually have some Apple //e's lying around. Maybe I'll dig up an ethernet card and see if i can get this to work.
    • 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.
  • Imagine.. (Score:5, Funny)

    by iLEZ (594245) on Saturday August 16 2003, @08:35AM (#6711944) Homepage
    Imagine a beowulf cluster of... Nah...
  • by travail_jgd (80602) on Saturday August 16 2003, @08:37AM (#6711952)
    "Pre-slashdotted for your convenience."
  • Cowabunga! (Score:2, Funny)

    by Anonymous Coward
    Seriously cool! I'm going to key it into my TRS-80 right now!
    • Somebody needs to attend the Vintage Computer Festival [vintage.org]! The TRS-80 Model I, II, III, 4, et al used the Z-80, not the 6502. Unless you mean the Color Computer, which (iirc) used the 6809. There was another one (Model 6000?) that used the 68000, iirc. But no 6502's.

  • by dbleoslow (650429) on Saturday August 16 2003, @08:41AM (#6711966)
    with my fax machine. It's not nearly as cool though.
  • by dioscaido (541037) on Saturday August 16 2003, @08: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.
    • 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.
    • That's exactly correct. Basically, anybody claiming to write any libraries with any speed or usability in BASIC are just writing a ton of in-line assembler. For instance, if you look online now, people claim to have their own 3d libraries in BASIC. They sure do, but it's just a bunch assembler wrapped up in SUBs.
    • by yellowstone (62484) on Saturday August 16 2003, @09: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.
      • by McDutchie (151611) on Saturday August 16 2003, @01:41PM (#6713289) Homepage
        Old-skool BASIC was really heinous:

        * Variable names limited to two characters
        This restriction was not universal, it depended on the dialect (there was, and is, no such thing as a standardized BASIC language).
        * Only data types are integers and strings
        I'm pretty sure that all variants had floating point data types as well.
        * No structured data types, only (fixed size) arrays
        But you could DIM them dynamically using a variable.
        * No names in control flow, just GOTO 100 and GOSUB 9000. No parameters for subroutines.
        Mostly true, but control flow was a bit better than that: there was also ON X GOTO 10,20,50,80 (which would go to line 10 if X=1, line 20 if X=2, etc) as well as ON X GOSUB in the same way.

        Also, there were user-defined one-line functions with parameters, which could even be recursive, as in: DEF FNX(P1,P2)=Y where X is the function name, P1 and P2 are parameters and Y is an expression.
        * Plus, it was typically interpreted, for extra slowness at run time.
        No argument there!
        • by yellowstone (62484) on Saturday August 16 2003, @10:43AM (#6712448) Homepage Journal
          Variable names limited to two characters

          What BASIC had that limitation? Surely none that I ever used as a kid (mid 80s).

          The BASIC on the Commodore C64/C128 did. The BASIC on the TI-99/4 did. The BASIC on the PDP-11/45 where I first programmed did by default (you could issue an EXTEND keyword to allow longer identifiers -- back then I didn't see why you'd want to bother with all that typing...)

          (mid 80s).
          Newb. ;-)
          • 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

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

              No, it's because in early Fortran compilers integer variables were letters from I to N (because they are INteger, see?).

              So, in Fortran you would start a loop using the first available integer variable, i, and then j, k and so on.

              How that was carried on to other languages is a mystery....
    • Obviously you aren't an old-school BASIC guy. That's how it worked. If you wanted to do anything fast, you wound up rolling a bunch of machine language inside a BASIC control loop.

  • Next... (Score:2, Interesting)

    someone will come up with a shell script webserver.
    • done already. This one is in bash...

      http://linux.umbc.edu/~mabzug1/bash-httpd.html
    • Re:Next... (Score:5, Interesting)

      by DrSkwid (118965) on Saturday August 16 2003, @10:34AM (#6712408) Homepage 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, @10:44AM (#6712452) Homepage 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 Mostly a lurker (634878) on Saturday August 16 2003, @08:52AM (#6712017)
    Isn't he worried about someone else commercialising this?
  • A lot of microcontrollers can be programmed in Basic-like languages. It's easy to write basic interpreters/compilers because of the limited features of the language. Remember that "pure" basic doesn't have a subroutine concept at all (besides the very limited GOSUB), and no local variables. Commercial PLC systems have been using Basic as the "high-level"-language of choice for ages. Though they are now more and more moving to IEC-61131-compatible languages like ST ("structured text") and graphical languages
  • ... 'stack' is in any way appropriate to describe TCP drivers.
  • by mhandlon (464241) on Saturday August 16 2003, @09:12AM (#6712085)
    I've looked at assembly and not understood it, I've looked at C and not understood it, and I think every time I have looked anything in perl I've not understood it. But, now the unthinkable has happened and I've looked at basic and not understood it.
  • data statements (Score:5, Informative)

    by magarity (164372) on Saturday August 16 2003, @09:12AM (#6712086)
    It's the chuncking through those data statements at the end that helps really beats up performance. Defining all those as strings at the beginning will ameliorate that problem.
  • It's interesting just because of the fact that it can be done. Impractical, but I'd be interested in seeing what else he can do with this thing (since he states that it is not finished yet, and just provided as a proof of concept). I don't forsee it ever becoming practical.

    What makes me laugh is that when I was using BASIC, I was printing a man to the screen as he went through the positions of a jumping jack. Clearing the screen after each position made it seem as though he was doing a jumping jack be
  • EhBASIC (Score:5, Funny)

    by iantri (687643) <iantri@@@gmx...net> on Saturday August 16 2003, @09:26AM (#6712133) Homepage
    And here I was thinking this was some sort of obscure Canadian BASIC..
  • EhBasic? (Score:4, Funny)

    by headkase (533448) <pickett.bill@gmail.com> on Saturday August 16 2003, @09:31AM (#6712156)
    When I first read its name, I thought it was Canadian. :)
  • Not new (Score:4, Informative)

    by wumpus188 (657540) on Saturday August 16 2003, @09:43AM (#6712217)
    Actually, Parallax [parallax.com] was doing this since what... 1992? They got TCP/IP stack for their BasicStamps too. But of course, their stuff runs a bit faster than 1MHz... :)
  • by BoneFlower (107640) <george.worroll@gma i l . c om> on Saturday August 16 2003, @09:51AM (#6712252) Journal
    Until it breaks mozilla while running fine in IE.
  • by sverrehu (22545) on Saturday August 16 2003, @10: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.
  • by MattBurke (58682) on Saturday August 16 2003, @02:19PM (#6713431) Homepage
    34040 DATA "HTTP/1.0 200 OK",$,"Content-Type: text/html",$,$
    34041 DATA "<HTML><HEAD><TITLE>Error 404</TITLE></HEAD><BODY BGCOLOR=#"

    is it just me who's spotted that the 404 page isn't really a 404? ;)
  • by extrasolar (28341) on Saturday August 16 2003, @11:50PM (#6715390) Homepage Journal
    I know rusty was trying to cut costs on kuro5hin.org, but this is rediculous.
    • Yes, actually. Look in your ports collection. A real quick grep turned this up:

      $ ls | grep basic
      bwbasic/
      gnomebasic/
      pbasic/
      wxbasic/
      y abasic/
    • BASIC rules!I want Basic back! Is there any Basic interpreters for my FreeBSD?

      Screw that - I want a version of FreeBSD written in BASIC

      • by pla (258480) on Saturday August 16 2003, @12:21PM (#6712909) Journal
        VB is alive and well, and used for pretty much the same reason as original BASIC - simplicity.

        I would agree it still lives, but disagree about your reasons...

        VB strips away all the simplicity normally present in BASIC, in that if you know basic, you don't necessarily know VB (very similar to C vs JAVA... They have very similar atomic statements, but the different paradigm makes proficiency in one not map 1-to-1 to the other).

        VB excels in making pretty GUIs under Windows. I have yet to find a language that makes creating a spiffy user interface anywhere *near* so easy. People rave about JAVA for GUIs, but I would say that, line-for-line, it takes just as much work as using pure Win32. Tk does fairly well, as long as you like the system default of everything, but if you want more control, it makes you jump through all sorts of unpleasant hoops. But VB... Just no way to beat its level of GUI-oneness.

        Unfortunately, it crawls when it comes to execution speed. I remember writing an app for a professor back in college, did nothing but text processing and a few simple stats to compile student evaluation surveys. Running through a list of only 30-50 students took almost two minutes. Incidentally, I prototyped it in C (but he wanted a spiffy GUI, and I hadn't yet mastered raw Win32), and the same thing would finish in well under a second.
    • by DrSkwid (118965) on Saturday August 16 2003, @09:30AM (#6712143) Homepage 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