Article:
 |
|
Write a Webserver in 100 Lines of Code or Less
|
| Subject: |
|
Perl's version |
| Date: |
|
2004-11-19 17:27:10 |
| From: |
|
merlyn
|
|
|
From the HTTP::Daemon manpage:
use HTTP::Daemon;
use HTTP::Status;
my $d = HTTP::Daemon->new || die;
print "Please contact me at: <URL:", $d->url, ">\n";
while (my $c = $d->accept) {
while (my $r = $c->get_request) {
if ($r->method eq 'GET' and $r->url->path eq "/xyzzy") {
# remember, this is *not* recommended practice :-)
$c->send_file_response("/etc/passwd");
}
else {
$c->send_error(RC_FORBIDDEN)
}
}
$c->close;
undef($c);
}
|
Showing messages 1 through 1 of 1.
-
Perl's version
2004-11-19 17:36:48
NeuralizR
[View]
Now you're comparing an http server built on top of a socket library to an http server built from a library that essentially contains all of the code for an http server. With the library, you just need to instance the Daemon object and write up some way to handle your events.
So, if your point is that perl is easier because there's a lot of libraries already out there for you and you don't need to write your own.... you win.
I personally found this article very useful as an example of how to do a LOT of different things in REALBasic. :D Writing a web server is not something you would do in RB just for the sake of writing one, but it'd be useful to integrate that functionality into an existing application. It is also nice just to have a real world example of how to use sockets correctly in RB. This makes it easier for someone to implement any kind of event style networking code. ;)