Thanks for that dngor! The first one is definitely what I meant I'm trying to do. Sorry for being too vague.

I was able to get something working using LeoNerd's IO::Async framework. If anyone cares to take a look, let me know if there are any obvious problems:

#####################3 server.pl use strict; use warnings; use diagnostics; use Time::HiRes qw(time); use IO::Socket::INET; use IO::Async::Stream; use IO::Async::Loop; my $loop = IO::Async::Loop->new(); my $server_socket = IO::Socket::INET->new( Listen => 5, ReuseAddr => 1, LocalPort => 8888, Proto => 'tcp', Blocking => 1, # This line is very important ) or die $!; $server_socket->autoflush( 1 ) or die $!; $loop->listen( handle => $server_socket, on_accept => sub { my ( $newclient ) = @_; $loop->add( IO::Async::Stream->new( handle => $newclient, on_read => sub { my ( $self, $buffref, $closed ) = @_; # $self->write( $$buffref ); warn 'READ: ', $$buffref; my $send_start = time; $newclient->send( 'ECHO: ' . $$buffref ); warn 'TIME TO SEND TO CLIENT: ', time - $send_star +t; $$buffref = ''; return 0; }, ), ); }, on_resolve_error => sub { print STDERR "Cannot resolve - $_[0]\n"; + }, on_listen_error => sub { print STDERR "Cannot listen\n"; }, ); $loop->loop_forever();
######################## client.pl use strict; use warnings; use diagnostics; use Time::HiRes(); use IO::Socket::INET; my $time = time; while() { my $client_socket = IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => '8888', Proto => 'tcp', ) or die $!; $client_socket->autoflush( 1 ) or die $!; my $send_start = Time::HiRes::time; sleep int rand 6; warn sprintf( "PID: %s, TIME TO SEND TO SERVER: %s, ELAPSED: %s\n" +, $$, Time::HiRes::time - $send_start, time - $time, ); $client_socket->send( sprintf( "PID: %s, TIME TO SEND TO SERVER: % +s, ELAPSED: %s\n", $$, Time::HiRes::time - $send_start, time - $time, + ) ); my $recv_start = time; sleep int rand 11; $client_socket->recv( my $buffer, 1024 ); warn sprintf 'TIME TO READ FROM SERVER %s: ELAPSED: %s GOT: %s', T +ime::HiRes::time - $recv_start, time - $time, $buffer; }

If any other framework authors would care to chime in *cough*mlehmann*cough* please feel free!


In reply to Re: Event based handling of multiple connections with AnyEvent by Anonymous Monk
in thread Event based handling of multiple connections with AnyEvent by bennymack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.