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.
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.)
25 seconds per page?
:-)
That seems very slow even for an 8-bit MCU. Maybe his basic interpreter just sucks?
Or, were these like huge ass PHP pages with mysql running in the background?
Tom
Someday, I'll have a real sig.
ten out of ten for style, but minus several million for good thinking.
//e's lying around. Maybe I'll dig up an ethernet card and see if i can get this to work.
I actually have some Apple
Imagine a beowulf cluster of... Nah...
You cant fight in here, its a war room!
is it written in basic or is it compiled and just provides an API? I would think the latter, but I'm not sure.
"Pre-slashdotted for your convenience."
Seriously cool! I'm going to key it into my TRS-80 right now!
with my fax machine. It's not nearly as cool though.
"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.
What days were these that you needed BASIC to actually run the machine? What did you used to do, fire up the interpreter and write a mini-shell or something? In BASIC??
Can the code really be called BASIC? It looks more like tons of in-line assembly code, wrapped in a few ifs and loops.
They said that you can't do any professional programming with Basic back in the old days. This is a great slap to the face of those people.
BASIC rules!I want Basic back! Is there any Basic interpreters for my FreeBSD?
I saw a bunch of GOSUB statements in there. Wimp! We don't need no stinkin' pseudo-functions! At least he didn't use RealBasic, which is more on the level of Pascal nowadays.
someone will come up with a shell script webserver.
Isn't he worried about someone else commercialising this?
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?
Somebody should implement a webserver using trained monkeys with abacuses. That should put an end to these "duct-tape and hamster webserver" boring stories.
-- Repeat with me: "There is no right to profits".
Pretty impressive. But I've got something better. I've got the Basic source code for pre-DOS. The one that Bill Gates "stole" from the dumpster.
Today Microsoft announced that it has contracted Lee Davison to write a brand new TCP/IP stack for upcoming versions of the Windows operating system, including Longhorn and a service release of Windows 2003 Server. "We hope that this ground breaking technology will usher in a new era of reliability and speed for our enterprise-level server products as well as our consumer operating systems," said a Microsoft spokesman....
Thanks dude! I know what I'll do on this weekend now!
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.
This server might be the soltution for DOSS attacks since he will responde too slowly to the request - its like an old man in the supermarket, takes his time and doing his job :D
Dont just mail it - Maileet
I was looking at the 6502 part and immediately thought "Commodore BASIC". So they made their own BASIC interpreter, very cool!
And since they made a custom BASIC, I had to take a look at the language reference. To be honest, it doesn't look that much advanced compared to Commodore BASIC v2 (apart of being custom-made and thus being way cooler), apart of some interesting machine language-related functions (word poke/peek). It may be whole lot better engineered and more efficient than the Microsoft-Commodore monstrosity, but there sure aren't that much more language features. You know, the kind of BASIC that Dijkstra called "mental mutilation", not the ones that are produced today.
So, it seems like a limited BASIC interpreter, which makes coding this server thing extremely impressive.
Back 15-10 years ago I was coding simple text adventures in Commodore Basic. Those worked just fine. A few months back I got a crazy idea to code a Tetris clone. That was painful. Very painful. Especially to someone who has, during these long years, got used to luxuries offered by C and Perl - simplest example of these would be local variables and named+parametrized subroutine calls.
A homebrew BASIC interpreter is nice, while it's a shame it's not as feature-packed; Writing a server in this thing is amazing.
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.
the first-choice scripting language would be basic. no, it would be too slow. maybe 6502 assembly... ;)
-- --
... 'stack' is in any way appropriate to describe TCP drivers.
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
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.
Oh this just takes me back.. Back to when I was in elementry school in the early 80's and working on an old NCR with two 5.25" floppy disk drives. Coded a text RPG on that in basic with two full levels.
:D
Then I got a Radio Shack color computer 2 with a tape cassette drive and a thermal printer that made like a cash register tape. Also had a nice 13" color tv monitor to hook it to. Luxury computing... mmmmmm... 16k of memory.
Coded a light cycles of Tron game on that cause I got tired of plopping quarters in the arcades. My elementry school teacher never got over the day I handed her a roll of paper that looked like a grocery reciept when it was actually a typed and printed book report from my Coco2.
~~ Behold the flying cow with a rail gun! ~~
Sounds a bit more like it should be from the "reinventing-the-wheel dept."
+5, Female
That BASIC stuff is boring (eg too easy to understand <g
Has anyone seen a webserver written in brainfuck yet? That would be real fun!
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 because of the processing speed.
It's amazing what some people will do to waste...errr, entertain themselves.
So what's the next revolution? A web server written in Brainf**k?
And here I was thinking this was some sort of obscure Canadian BASIC..
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
When I first read its name, I thought it was Canadian. :)
Shh.
Whoever wrote that must have had a lot of spare time on their hands! I can't even get a simple game to work in BASIC without LOTS of debugging of problems that are problems because of the stupid nature of the language!
This reminds me of a similar project I did about 6 months ago. A Webserver on the Bx24 microprocessor. The whole system fit on a 1.5 inch by 3.5 inch breadboard and served pages off of an EEPROM. The TCP/IP stack was handled by the ethernet controller thank god, but that made room on the processor for a really lame inline assembly like script that could embed into pages being served. Here is the only picture of the server I can find
Don't write TCP/IP stacks and web servers in Basic!
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... :)
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.
-- Slashdot: When Public Access TV Says "No"
OK so all you youngsters have been raised on these unreadable to regular folks languages like C (where you, yes you, get to be the frigging precompiler and speak the machines language rather then the other way around) may think they're the cats whiskers, but for an old fart like me who was raised on process based code it's nice to see someone still doing clever stuff within the limitations of a language. Fact is that for all this fancy (read silly) argument about object oriented vs. procedure oriented vs. whathave you oriented languages, to the machine it still looks like 10111010 10101011 00101110. The rest of the debate is about how well the langague is readable to humans and how easy or hard it is to code some particular function. If you like languages that make you do most of the work and write code that requires days to read even simple functions (if written by some other programmer) then more power to you. Me, I vote that it's lazy compiler writers that have sluffed off the work on you. If you want to work that hard then program in Assembly by all means. I like Basic, I've yet to find a damn thing that can't be done in it, and it's written the way HUMANS think, not computers. I want my source readable, it's the compilers job to make it nice for the computer. So feeeeggghhh to you Basic bashers.
P.S. I started writing code in RPG. As far as I'm concerned BASIC was a God Send.
This doesn't even cover buffer overruns > 64K -- man, that's weak.
Keep your packets off my GNU/Girlfriend!
Ooh, moderator points! Five more idjits go to Minus One Hell!
Delendae sunt RIAA, MPAA et Windoze
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
If that impresses you, what do you think about the C64 streaming server? 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).
I mean, c'mon: BASIC ... must be pretty hard to write code with buffers overflows which is obviously needed in a TCP/IP-stack.
Who saw that and thought lda #254, $e2 - wtf, illegal opcode? :-)
... 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.
...Go on then. Post it up.
You know you want to.
Better yet, write one in F*ck F*ck.
You know you want to.
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.
VB is alive and well, and used for pretty much the same reason as original BASIC - simplicity. Although there are many additions, old stuff still works. The other day I "fixed" a friends program with some old fashioned for loops and labels.
Finally, a use for my VIC-20.
Prevent email address forgery. Publish SPF records for y
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.
10 PING WEBSITE 20 GOTO 10 I shudder at the thought! ;)
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.
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-
two letter variables? not in my basic
and what about "on gosub" ?
every day http://en.wikipedia.org/wiki/Special:Random
any one remember PIP on the altair?
in any case when java came along I bet that one reason MS saw it as a threat was that between java and a browser you really did not need to have an OS at all. you just needed to have the computer wake up in java and then write the OS or load OS du jour written in java. applications would be simply forked java jobs. java would be doing all the system level connection.
you might say that well java was now the OS. that i'm just playing word games here. but if that were really true then why did you have to pay 200$ to microsoft for your Windows operating system but you got JAVA free? if you could replace the OS with java then well redmond is out of the OS bussiness.
not a pipe dream at all since that's how it all began way back when
Some drink at the fountain of knowledge. Others just gargle.
I can just see the business plan around this thing...
if it had happened pre-year 2000:
Business-Guy: "See... we can pick up a bunch of these Z80's from the local electronics store for about $3 a pop, slap them together into a cluster config, and advertise that our webservers are not only CLUSTERED, but have a failure rate MUCH less than IIS and Apache combined! Here's how we make that claim: if on average (pulls number out of fanny) 1 in every 50K pages fails to display, it'll literally take us 2.8 years before we have a single failure!"
Venture-Capitalist: "GENIUS! Here's $50mil in money from blue collar workers... we expect brochures by next year!"
;)
Diplomacy is the art of saying, "Nice doggie!" until you can find a rock.
Yeah, we need more BASIC systems programmers. Maybe they'll rewrite both Visual BASIC and Windows in Visual BASIC next. Hey, does Visual BASIC implement POKE and PEEK? That would be really kewl.
Hey the code are violation our intellectual property!
I can't tell you which line, but GOSUB 10000 and the command REM are violating our IP..!!
Watch out.
(btw. you may license the use of REM for a small fee)
McBeef
CEO
(TDP)-1
In order to form an immaculate member of a flock of sheep one must, above all, be a sheep.
--- Gary McClellan
You are teh funny
You are teh funny.
The use of i and j as loop counters come from Fortran. Fortran IV had implicit typing based on the first letter of a variable name. I - M were implicity integer. I think of i and j as variables for when the language is too low-level to have foreach.
Life is a psychology experiment gone awry.
It's a Model 1, Level 1. I'm using the cassette port to talk with my cable modem.
Translating to Z80 op codes is no big deal, I just convert to Zilog as I'm entering the text. And I have 4k of linear address space to work with!
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?
A server written like...
1248 goto 10
The VB compiler makes very efficient compiled code. The reason why your program was slow is that string operations become extremly expensive on large strings. Namely building a large string from many different small pieces in a loop is murder. Some examples:
Sloooow:
For lIndex = 1 to 10000
sLarge = sLarge & sSmall1 & sSmall2 & sSmall3
Next lIndex
As sLarge grows copying it gets more and more expensive. In this example sLarge will be copied three times as each small string gets appended in turn.
2-3x faster:
For lIndex = 1 to 10000
sLarge = sLarge & (sSmall1 & sSmall2 & sSmall3)
Next lIndex
Using parens to group the small strings means the three small ones will be first formed into one string before being appended to sLarge, meaning space for sLarge is only reallocated once.
The really fast way to build large strings in VB is to keep them in small chunks in an array of fixed size strings and when done assembling do a Join.
Let's port the Apache server into the ATARI 800 and do some serious web gaming.
Imagine a Beowulf cluster of these!
Ok, this has been said before but then I thought of an application...
Next time Slashdot points to your web site, have a primary web server redirect the duty of serving the web page to one of a beowulf cluster of these. Because of the intrinsic delay your site won't be Slashdotted. K00l!!
Donte Alistair Anderson Roberts - hi son!
Karma: Chameleon
The web server at humanclock.
He better have cut a deal with SCO before going public. Can you imagine the license that SCO would want for such a thing?
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.
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!
Working toward a usable PDA environment in the spirit of Newton OS: Dynapad
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...
-- Slashdot: When Public Access TV Says "No"
I note that one can place their own HTML for the web page in lines 32000 up, and that there is a misspelled word in line 32004.
Offtopic, yes I know.
Anyhow, writing a web server in basic should qualify for som karma points! =)
computers let you make more mistakes faster, with the possible exception of handguns and tequila.
Now my Apple ][ plus can serve web pages!
I know rusty was trying to cut costs on kuro5hin.org, but this is rediculous.
It's called IIS.
Look, if you're going to talk networking to a programmer, you gotta simplify it in terms they can understand.
Help us build a better map!
So I pondered and decided to investigate chroot ./bin ./bin/tcpserver ./bin/webserver.rc ./bin/cat ./bin/date ./bin/head ./bin/tr ./bin/wc ./bin/awk ./bin/magic.mime ./bin/file ./bin/test ./bin/rc ./bin/ls ./bin/server.rc ./bin/sed ./document_root ./document_root/index.html ./usr ./usr/libexec ./usr/libexec/ld-elf.so.1 ./usr/lib ./usr/lib/libc.so.4 ./usr/lib/libgnuregex.so.2 ./usr/lib/libm.so.2
: /home/matt/awkwebserver/ bin/server.rc
/bin/tcpserver 192.168.1.100 8012 /bin/webserver.rc -u 80 -g 80
I had to make the following tree
then as root
chroot
and bin/server.rc looks like
#!bin/rc
and viola : a secure* read only web server
You can add more options to tcpserver to limit the connections / memory usage etc.
20 seconds to respond seems to sound wrong I hope
There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
In fact, they own all of us...
Think about the following: (a) the human brain scales without problems to many millions of neurons, (b) it has parallelism unreached by any computer - anytime (c) it exceeds the reliability of unix - my brain hasn't crashed for decades (d) it can be used to build clusters - those are called teams.
Clearly, this could not have been possible without access to the original unix sources. Therefore SCO has intellectual property in everybody's dna and all derivative work.
So let's just hope they don't realize this and claim our immortal souls and our first-born children... Or maybe they could declare us invalid...