Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



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 mcgroarty ( 633843 ) <{moc.liamg} {ta} {ytraorgcm.nairb}> on Saturday August 16, 2003 @08:33AM (#6711938) Homepage
    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.)
  • by Kevinv ( 21462 ) <kevin&vanhaaren,net> on Saturday August 16, 2003 @08:35AM (#6711942) Homepage
    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.
  • 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!
    • it would be much faster if you hook the optical reader to your Epson DMP and let it scan in the source code, after you printed it on your color dyesub printer first, of course
    • Re:Cowabunga! Nope! (Score:3, Informative)

      by UncleRoger ( 9456 )

      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.

    • ...except, how will you serve it? this guy made his own ethernet board and wrote a card/platform specific driver for it- also in BASIC of course. :) Or, were you one of the lucky folks to get one of the eTRS-80 Model 8 with on board ethernet? My uncle has one- it is amazing! He browses the web using Contiki, it's pretty sweet.
  • 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.
      • No names in control flow, just GOTO 100 and GOSUB 9000. No parameters for subroutines.

        In some of the later ones you could GOTO a variable name. This led to some really interesting code such as:

        10 LET L1=100
        20 PRINT "ENTER NUMBER:"
        30 READ A
        40 GOTO 100 + (A * 10)

        100 (blah blah blah)
        105 GOTO 200
        110 (blah blah blah) ...

      • 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!
    • 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 :)

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

    by ihummel ( 154369 )
    someone will come up with a shell script webserver.
    • Re:Next... (Score:3, Interesting)

      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) 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) 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
    • You're confusing "pure" BASIC with line-numbered BASIC from a quarter century ago. ANSI BASIC or any commercially available dialect have long supported true procedures, functions, etc.

  • ... 'stack' is in any way appropriate to describe TCP drivers.
  • by mhandlon ( 464241 ) on Saturday August 16, 2003 @09:12AM (#6712085) Homepage
    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@gmxSTRAW.net minus berry> 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 ) on Saturday August 16, 2003 @09:31AM (#6712156)
    When I first read its name, I thought it was Canadian. :)
  • Don't write TCP/IP stacks and web servers in Basic!
  • 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 ) <anniethebruce@gma[ ]com ['il.' in gap]> on Saturday August 16, 2003 @09:51AM (#6712252) Journal
    Until it breaks mozilla while running fine in IE.
  • This story will surely provoke a batch of silly and ignorant BASIC-bashing posts from people who think learning about programming stops when they choose a language, but consider:

    Suppose BASIC didn't exist, and some contemporary open source developer released a full-blown compiler for a language equivalent to ANSI BASIC, or the dialect supported by PowerBasic, or even Visual Basic. Some folks, I imagine, might like what they see.

    • I can't help but laugh when someone makes a post like this- and folks moderate it as Flamebait. I mean, the content of the post is obviously true, and moderating it as flamebait only confirms this. Slashduh- gotta love it!
      • I usually don't even notice if one of my posts is moderated (What the hell is moderation anyway, and why would anyone care?), but you're right -- this is especially silly. Sort of illustrates that this is a cult (there's only one way to think) and not a community.

        Somehow, I can't get rid of this image of some 19-year old sophomore slouched over a keyboard in his room in the dorm...
  • This doesn't even cover buffer overruns > 64K -- man, that's weak.

  • If that impresses you, what do you think about the C64 streaming server [dunkels.com]? It's not in BASIC, but it's running on about the same CPU (the C64's 6510 is a 6502 with additonal lines for the tape recorder).
  • 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.
  • PowerBASIC (Score:2, Interesting)

    by arashiakari ( 633150 )
    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 st

  • 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

  • BASIC Webserver (Score:2, Interesting)

    by gmcclel ( 43020 ) *
    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 MattBurke ( 58682 ) on Saturday August 16, 2003 @02:19PM (#6713431)
    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? ;)
  • Nooooooooo (Score:2, Funny)

    by cnb ( 146606 )
    A server written like...

    1248 goto 10
  • Since so many people have so much free time, why don't they do something useful, instead of hacking out such impractical applications ? Linux is in need of many things.
  • 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.

Avoid strange women and temporary variables.

Working...