MiggyMan has asked for the wisdom of the Perl Monks concerning the following question:
use warnings; use AnyEvent; use AnyEvent::Socket; use AnyEvent::Handle; use Data::Dumper; my $port = 7777; my $cv = AnyEvent->condvar; tcp_server undef, 7777, sub { my ( $fh, $host, $port ) = @_; warn "Accepted connection from $host:$port\n"; create_handle( $fh, 0 ); }; sub create_handle { my ( $socket, $exit_on_close ) = @_; my ( $shandle, $thandle ); my $destroy = sub { $shandle->destroy; $cv->send if $exit_on_close; }; $shandle = AnyEvent::Handle->new( fh => $socket, on_error => $destroy, on_close => $destroy, ); $shandle->on_read( sub { if ( $shandle->rbuf eq "marco" ) { $shandle->push_write("polo"); } print "A\n"; $shandle->rbuf = ''; print $shandle->rbuf; } ); $shandle->on_eof(undef); } $cv->recv;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting port number with AnyEvent::Socket
by Anonymous Monk on Jun 13, 2010 at 11:34 UTC | |
by MiggyMan (Sexton) on Jun 13, 2010 at 13:04 UTC | |
by Anonymous Monk on Jun 13, 2010 at 13:07 UTC | |
by MiggyMan (Sexton) on Jun 13, 2010 at 14:30 UTC | |
|
Re: Getting port number with AnyEvent::Socket
by Khen1950fx (Canon) on Jun 14, 2010 at 01:01 UTC |