Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: IO::Socket/multiple connections related

by dk (Chaplain)
on Jul 02, 2009 at 17:15 UTC ( [id://776806]=note: print w/replies, xml ) Need Help??


in reply to IO::Socket/multiple connections related

In addition to the list of event frameworks kindly provided by tfoertsch, I would like to add my own IO::Lambda, which I really wish had more adoption and hope everyone else would excuse me for PRing. Anyways. If you feel like trying it, I'd be glad to provide help. Using it, your task would be written basically as such:
use strict; use IO::Socket; use IO::Lambda qw(:all); use IO::Lambda::Socket qw(:all); my $server = IO::Socket::INET-> new( Listen => 5, LocalPort => 10000, Blocking => 0, ReuseAddr => 1, ); die $! unless $server; lambda { context $server; accept { # socket with an incoming connection my $conn = shift; # tell the loop to accept() again again; unless ( ref($conn)) { warn "accept() error:$conn\n" unless ref($conn); return; } # now read all from the new connection context $conn; readable { my $buf; my $n = sysread( $conn, $buf, 65536); unless ( defined $n) { warn "error reading:$!\n"; } elsif ( $n == 0) { warn "connection closed\n"; } else { print $buf; again; } }} }-> wait;
Hope it helps

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://776806]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found