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

Re: Event based handling of multiple connections with AnyEvent

by bennymack (Pilgrim)
on Nov 04, 2008 at 12:10 UTC ( [id://721364]=note: print w/replies, xml ) Need Help??


in reply to Event based handling of multiple connections with AnyEvent

Update: working AnyEvent version.

#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use POSIX; use EV(); use AnyEvent(); use AnyEvent::Handle(); use IO::Socket::INET(); use Socket qw(SOCK_STREAM); my $server_socket = IO::Socket::INET->new( Listen => 5, ReuseAddr => 1, LocalPort => 8888, Blocking => 0, Type => SOCK_STREAM, ); $server_socket->autoflush( 1 ); my $child = AnyEvent->condvar; my $server_socket_watcher = AnyEvent->io( fh => $server_socket, poll => 'r', cb => sub { my $client_socket = $server_socket->accept; my $client = AnyEvent->condvar; my $handle = AnyEvent::Handle->new( fh => $client_socket, on_read => sub { my( $self ) = @_; warn $$, ' GOT: ', $self->rbuf; if( $self->rbuf =~ /QUIT/ ) { warn $$, ' QUITTING'; $client->send; } }, on_drain => sub { warn $$, ' drain '; }, on_error => sub { print "Client connection error\n"; $clie +nt->broadcast; }, ); $client->recv; warn $$, ' CLIENT: recv'; }, ); warn $$, ' $child->recv'; $child->recv; warn $$, ' CHILD: done'; exit;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-18 02:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found