use IO::Select; use IO::Socket; $lsn = new IO::Socket::INET(proto => 'tcp', Listen => 1, LocalAddr => + '192.168.6.92:9090', Reuse => 1); print "Error in socket :$!\n"; $sel = new IO::Select( $lsn ); $i = 0; $IPHASH= {}; while(@ready = $sel->can_read) { foreach $fh (@ready) { if($fh == $lsn) { # Create a new socket $new = $lsn->accept; $HostAdd = $new->peername(); ($Port , $Myadd) = sockaddr_in($HostAdd); $IPAdd = inet_ntoa($Myadd); $sel->add($new); $IPHASH->{"$IPAdd"} = $new; } else { # Process socket $InputBuffer; $OutputBuffer; $Delay = 0.1; vec($InputBuffer, fileno($fh),1)=1; ($Found, $Temp) = select($OutputBuffer=$Inp +utBuffer, undef, undef, $Delay); my (@Bits) = split (//,unpack("b*", $OutputBuffer)); $handle = fileno($fh); recv ($fh, $Received_Message, 20, 0); $HostAdd = $new->peername(); ($Port , $Myadd) = sockaddr_in($HostAdd); $IPAdd = inet_ntoa($Myadd); $fh = $IPHASH->{$Received_Message}; #vec($InputBuffer, fileno($fh), 1)=1; #($Found, $Temp) = select($OutputBuffer=$I +nputBuffer, undef, undef, $Delay); # my (@Bits) = split (//, unpack("b*", $Out +putBuffer)); # $handle = fileno($fh); print "::: $Received_Message :::: \n"; $fh->autoflush(1); # Maybe we have finished with the socket $sel->remove($fh); $fh->close; } $i++; } }
In reply to vec and unpack by dharanivasan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |