Hm I have no idea what an "F5 appliance" is. But, I'd love to understand what you mean by:
but the said 'right piece of code' works correctly only with one connection, when I hand that same code the socket connection from the multi connection version, it doesn't work correctly.
The socket returned from accept, will only be connected to one client at any given time. It could come from any of the five client machines. Discovering which machine (ip address) it comes from is easy. So routing each incoming client connection to a thread that is dedicated to dealing with that connection should be very easy.
Ostensibly:
sub client1 { my $fno = shift; open my $client, '+<&', $fno or die; while( <$client> { if( /... / { print $client ...; } elsif( /.../ ) { print $client ...; else { print $client ...; } } } sub client2 { ... } sub client3 { ... } sub client4 { ... } sub client5 { ... } my %lookup = ( 'xxx.xxx.xxx.xxx' => \&client1, 'yyy.yyy.yyy.yyy' => \&client2, ... ); my $lsn = IO::Socket::INET->new( Listen => 5, LocalPort => $port ); while( my $client = $lst->accept ) { my $addr = $client->peerhost; thread->create( $lookup{ $addr }, fileno( $client ) )->detach; }
And that's pretty much it. Each client (type/machine/whatever) gets a dedicate thread that talks to it and only it. That thread runs a simple conversation dedicated to that clients needs. Even concurrent clients from a given machine get a thread dedicated to just that conversation.
No complicated, state machine mixing concerns of listening for clients; accepting input and sending output all together in a spaghetti nightmare of global variables and transient states. But, people seem to like complicated.
POE is extraordinarily clever code. Trouble is, it seems to require extraordinary programmers to use it. And if one them has coded a wheel that does exactly what you need to do, and you can find it, and understand the documentation, then you can hire it and you're set to go.
But need something slightly different to what's available and you're in the lap of the gods awaiting yet another distribution tailored to your exact needs.
In reply to Re^3: Socket Traffic Cop
by BrowserUk
in thread Socket Traffic Cop
by sans-clue
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |