in reply to IO::Socket simple server

Well you have other good answers by my 2 cents is this: You are reinventing he wheel making a socket server, and there is a lot of complication because you have to handle different client instances, and handle the various situations to manage the sockets/sessions/clients. Then you also have the problem of framing/structuring the info over the tcp stream itself. You are much better just jumping straight to something already event driven and using a higher level protocol so sockets, connections, tcp, are all abstracted away.

An example is a simple HTTP server:

use AnyEvent; use AnyEvent::HTTPD; # Create server my $server = AnyEvent::HTTPD->new(host => '127.0.0.1',port => 3333); # Setup response for requests $server->reg_cb ('/test' => sub { my ($obj, $req) = @_; print "Got message '".$req->content."' from client ".$req->client_ +host.":".$req->client_port."\n"; $req->respond([200, 'ok', { 'Content-Type' => 'text/plain' }, 'Hel +lo' ]); }); AnyEvent->condvar->recv; #wait forever

For the client use LWP::UserAgent, or even AnyEvent::HTTP client:

use AnyEvent; use AnyEvent::HTTP; my $cv = AnyEvent->condvar; http_post "http://127.0.0.1:3333/test", "99", persistent=>1, sub { my ($data, $headers) = @_; print "Got back message '$data' from server\n"; $cv->send; # stop waiting }; $cv->recv; # Wait for response