Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Commands for IO::Socket

by Anonymous Monk
on Feb 15, 2001 at 23:00 UTC ( #58684=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:


Using IO::Socket, I've managed to make this perl script that acts like a super super small web server. What it does, is it opens port 8000 on my comp, and when a person requests for my ip with the 8000 port number, it will print out to the client an html page.

If the client, for example types:

Is there a command that I can use to get the last part of the url that the user typed (in this case aaa.mp3)?

Ralph :)

Replies are listed 'Best First'.
Re: Commands for IO::Socket
by zigster (Hermit) on Feb 15, 2001 at 23:28 UTC
    Use HTTP::Demon As mr Merlyn says it does everything that you want (and much of what you have already done) specifically if you look at the example on the web page here you will see code sample that does what you want I reproduce it below, slightly modified.
    use HTTP::Daemon; use HTTP::Status; my $d = new HTTP::Daemon; 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 "/aaa.mp3") { $c->send_file_response("aaa.mp3"); } else { $c->send_error(RC_FORBIDDEN) } } $c->close; undef($c); }
    Remember next time tho to look for a wheel before you build one. *grins* good coding.

Re: Commands for IO::Socket
by merlyn (Sage) on Feb 15, 2001 at 23:08 UTC
Re: Commands for IO::Socket
by Anonymous Monk on Feb 16, 2001 at 04:43 UTC
    wait... using zigster's code, what i want to do works perfect.

    i don't know why i didn't realize that.

    ralph :)
      hmmm.... I hope I don't get jumped on here, but perhaps (s)he is not using the HTTP::Daemon module because (s)he is trying to learn a new way of doing something.

      I'm nowhere near being "just another perl hacker"; I'm more like "learning as much as I can so some day maybe I can be just another perl hacker." Often I find myself doing things the "hard" way instead of using Module::that::does::everything::you::want *because* if I just use the module, how will I improve my knowlege and skill?

      (ignore me if what's I've said sounds stupid.)

Re: Commands for IO::Socket
by Anonymous Monk on Feb 16, 2001 at 04:36 UTC
    the thing is that with http::daemon i can't serve files to the client. that's why i'm using io::socket. unless somebody know how to do it.

    isn't there a command in the io::socket module??

Re: Commands for IO::Socket
by SilverB1rd (Scribe) on Feb 16, 2001 at 00:44 UTC
    Nice IP address! most likely dsl, maybe cable.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://58684]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2022-11-26 16:55 GMT
Find Nodes?
    Voting Booth?