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.

56 of 251 comments (clear)

  1. Down in three seconds flat by mcgroarty · · Score: 5, Funny

    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. :-)

    1. Re:Down in three seconds flat by ultrapenguin · · Score: 5, Informative

      NetRange: 169.254.0.0 - 169.254.255.255
      is one of those "non-routable private IP address spaces".

      RTFRFC

    2. Re:Down in three seconds flat by Anonymous Coward · · Score: 5, Funny

      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. :-)

      Here you go :)

    3. Re:Down in three seconds flat by Kevinv · · Score: 4, Funny

      How could you tell if it were slashdotted? 20 seconds per page is already a slashdotted server....

    4. Re:Down in three seconds flat by FyRE666 · · Score: 5, Funny

      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. :-)

      Yeah, and anyone stupid enough to believe it'll work outside of a local network should also try 127.0.0.1 for a cool Pr0n site!

    5. Re:Down in three seconds flat by beebware · · Score: 5, Funny

      Cool - you're right - there is some really good porn on http://127.0.0.1/ , but it must be a really old site and I'm sure I've seen it before...

    6. Re:Down in three seconds flat by fredrikj · · Score: 2, Funny

      Yeah, and anyone stupid enough to believe it'll work outside of a local network should also try 127.0.0.1 for a cool Pr0n site!

      Well, if you'd open 127.0.0.1:31337 and discover a kiddie porn site, you can be pretty sure there's a trojan somewhere on your computer :P

      Unless, of course...

    7. Re:Down in three seconds flat by Isbiten · · Score: 2, Funny

      I just get an apache test page, are you sure it's up? ;)

      --
      I fought the corporate America, and the corporate America bought the law.
  2. How long til it gets slashdotted? by gellenburg · · Score: 2, Funny

    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.)

    1. Re:How long til it gets slashdotted? by gellenburg · · Score: 5, Funny

      Hmm... you're right.

      This "BASIC" Webserver & TCP/IP Stack will go down in the annals of History as being the first ever webserver to become /.'ed before it's address even makes it to /. to begin with. :-)

  3. To quote Zahpod Beeblebrox... by Kevinv · · Score: 5, Funny

    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.

  4. Imagine.. by iLEZ · · Score: 5, Funny

    Imagine a beowulf cluster of... Nah...

    --
    You cant fight in here, its a war room!
  5. 20-35 Seconds Per Page?!? by travail_jgd · · Score: 5, Funny

    "Pre-slashdotted for your convenience."

  6. Cowabunga! by Anonymous Coward · · Score: 2, Funny

    Seriously cool! I'm going to key it into my TRS-80 right now!

  7. I get a slightly faster transfer speed by dbleoslow · · Score: 5, Funny

    with my fax machine. It's not nearly as cool though.

  8. 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 xiangpeng · · Score: 2, Insightful

      Well, ultimately it still have to go thru the ehBASIC interpreter, which more or less defines it as a "BASIC" program.

      Guess only BASIC purist will cry foul at this :)

      --
      You must defeat Sheng Long to stand a chance.
    4. Re:Looks more like assembler to me... by yellowstone · · Score: 4, Informative
      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. ;-)
      --
      150 Opening BINARY mode data connection for slashdot.sig (129323052 bytes).
    5. Re:Looks more like assembler to me... by Arker · · Score: 2, Informative

      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.

      --
      =-=-=-=-=-=-=-=-=-=-=-=-=-=-
      Friends don't let friends enable ecmascript.
    6. 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.
    7. Re:Looks more like assembler to me... by at_18 · · Score: 2, Informative

      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....

    8. Re:Looks more like assembler to me... by McDutchie · · Score: 4, Informative
      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!
  9. Re:how? by mcgroarty · · Score: 2

    Fat-fingered the paste. Rather, the source code is here.

  10. 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
  11. Source code has no copyright notice by Mostly+a+lurker · · Score: 5, Funny

    Isn't he worried about someone else commercialising this?

    1. Re:Source code has no copyright notice by henrik · · Score: 2, Informative

      You don't need any copyright notice. You always own the rights to your original work no matter what.

  12. 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.
  13. Not really that uncommon by i_really_dont_care · · Score: 2, Informative

    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.

  14. I must be getting rusty. by mhandlon · · Score: 5, Funny

    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.

    --
    Nyquil = Nectar of the devil
  15. data statements by magarity · · Score: 5, Informative

    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.

  16. Re:WOW! And they said.. by BabyDave · · Score: 3, Funny
    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

  17. EhBASIC by iantri · · Score: 5, Funny

    And here I was thinking this was some sort of obscure Canadian BASIC..

  18. 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
  19. EhBasic? by headkase · · Score: 4, Funny

    When I first read its name, I thought it was Canadian. :)

    --
    Shh.
  20. 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).
  21. Not new by wumpus188 · · Score: 4, Informative

    Actually, Parallax 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... :)

  22. Re:Oh good... by AndroidCat · · Score: 2, Informative
    You might want to do a search on "Tiny Basic". After BillG wrote his snooty anti-piracy letter way back when, some of the first open source projects were a number of Tiny Basic interpreters. (It's how Dr. Dobb's got its start.)

    They were slow and limited, but playing with them and extending them was a great way to learn. After those came the Small C compilers--never looked back.

    --
    One line blog. I hear that they're called Twitters now.
  23. it isn't complete by BoneFlower · · Score: 4, Funny

    Until it breaks mozilla while running fine in IE.

  24. R *this* FRFC. by L.+J.+Beauregard · · Score: 4, Informative
    There are more special IP ranges than the private network ranges in RFC 1918. They are documented in RFC 3330. The one in question is:

    169.254.0.0/16 - This is the "link local" block. It is allocated for communication between hosts on a single link. Hosts obtain these addresses by auto-configuration, such as when a DHCP server may not be found.
    --
    Ooh, moderator points! Five more idjits go to Minus One Hell!
    Delendae sunt RIAA, MPAA et Windoze
    1. Re:R *this* FRFC. by oldmildog · · Score: 2, Funny

      Ah, good link. Thanks. I always thought Microsoft pulled that IP address out of their ass for workstations that can't reach the DHCP Server. MS following an RFC... what a crazy world.

      --
      They have the Internet on computers now?
  25. 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
  26. Am I the only one by pommiekiwifruit · · Score: 2, Funny

    Who saw that and thought lda #254, $e2 - wtf, illegal opcode? :-)

  27. 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.

  28. 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.
  29. 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.

  30. Re:Cowabunga! Nope! by UncleRoger · · Score: 2, Informative

    Somebody needs to attend the Vintage Computer Festival! 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.

    --
    Stupid people will be persecuted to the fullest extent allowed by law.
  31. Why so "impossible"? by ant_slayer · · Score: 2, Informative

    Okay, I recognize the value of doing this (as a hobbyist myself). The fortitude required to accomplish such a feat is noteworthy. However, I have noticed a strange trend in these kinds of posts on Slashdot. Why do so many people respond with comments like, "I didn't know it could be done!"?.

    Technically, all of these languages are mathematically reducible to Turing machines. Thus, they are all *technically* able to perform the same tasks (ok, sure, you might have to extend your interpreter/compiler to handle things like syscalls, but hey, it's within the scope of reasonability). We could effectively use any programming language to produce any program. If the first web server is written in C, then by mathematical extension, we know that it could also be written in Perl, Forth, Fortran, and even BASIC. The difference is just that it might be a royal pain.

    I don't mean to denigrate the work this guy did -- in fact I'm amazed that he did it. But I'm not amazed *that it's possible*.

    What should elicit such responses? If the guy wrote a web server in HTML (a markup language). That is theoretically impossible. There are all kinds of languages that are not reducible to Turing machines -- make a web server using nothing but regular expressions and *I'll* say "Wow, I didn't know that was possible!"

    -Josh O-

  32. Re:Are you kidding? by pla · · Score: 4, Insightful

    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.

  33. 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
  34. When is a 404 not a 404? by MattBurke · · Score: 3, Insightful

    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? ;)

  35. Nooooooooo by cnb · · Score: 2, Funny

    A server written like...

    1248 goto 10

  36. This explains everything by extrasolar · · Score: 2, Funny

    I know rusty was trying to cut costs on kuro5hin.org, but this is rediculous.