sub processit { my ($lclient,$lfileno,$lpeer) = @_; #local client my $sel_cli_id = $num_of_client; if($lclient->connected){ while(<$lclient>) { if ($peerC eq '127.0.0.1') # tcp client from localhost is used just to send commands to other connected clients { my(@comm) = split(/:/, $_); my $sel_clix = $comm[0]; my $commandC = $comm[1]; for ($p=0; $p<=$#Mdevices; $p++) { if ($Mdevices[$p][0] eq $sel_clix) { $sel_cli2 = $Mdevices[$p][1]; } } foreach my $fn ($sel_cli2) { if ($sel_cli2) { open my $fh, ">&=$fn" or warn $! and die; print "\n $lclient $sel_cli2 Command sent to: $sel_clix Command: $commandC"; print $fh "$commandC\n" } else { print "\n $lclient Device: $sel_clix NOT avaiable to receive command\n"; } } } else { print "COMMAND RESPONCE: $_"; } } } #close filehandle before detached thread dies out close( $lclient); #remove multi-echo-clients from echo list @clients = grep {$_ !~ $lfileno} @clients; }