Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
The stupid question is the question not asked
 
PerlMonks  

Re: Listening on an HTTP port

by ryddler (Monk)
on Jan 04, 2001 at 18:48 UTC ( [id://49840]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Listening on an HTTP port

Check the docs on IO::Socket. Meantime here's a snip I played with to experiment with basic server listening...

#!/usr/bin/perl -w use strict; use IO::Select; use IO::Socket; my ($data, $fh); my $ipc_select = IO::Select->new(); my $IPC_SOCKET = new IO::Socket::INET(Listen => 5, LocalAddr => 'localhost', LocalPort => 9000, Proto => "tcp" ); print "SOCKET = $IPC_SOCKET\n"; $ipc_select->add($IPC_SOCKET); print "Listening...\n"; while (1) { if (my @ready = $ipc_select->can_read(.01)) { foreach $fh (@ready) { if($fh == $IPC_SOCKET) { #add incoming socket to select my $new = $IPC_SOCKET->accept; $ipc_select->add($new); print "incoming connection...\n"; } else { # Process socket if (recv $fh,$data,1024,0) { print $fh $data; print "$data"; } else { $ipc_select->remove($fh); $fh->close; } } } } }

You can run this script, and then telnet in on port 9000 (or whatever other port you set it to listen on in 'localport') and it will echo your typing...

ryddler

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://49840]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.