I had a couple questions in regards to using IO::Select - the first being, how do I select() specifically which client/process I want to speak to, and more importantly, when used in this manner, will the socket/connection be bidirectional (can I both read and write?).
(see ... ??? comments in code snippet below)
#this sets up $main_sock to handle multiple connections...??? $readable_handles = new IO::Select(); $readable_handles->add($main_sock); #this returns an array of readable (and writeable) #handles/connections...??? $new_readable) = IO::Select->select($readable_handles, undef, undef+, +0); #So now I can iterate through this array just like I would #for any other, except it is an array of "connections"... foreach $sock (@$new_readable) { #in the case that ($sock == $main_sock) this means that #I need to listen for & add any new connections to the #list of $readable_handles, but why not to $new_readable #as well...??? if ($sock == $main_sock) { $new_sock = $sock->accept(); $readable_handles->add($new_sock); } else { $buf = <$sock>; if ($buf) { #does the line $readable_handles->can_write() mean that #these handles are not bidirectional...??? print "$buf\n"; my @sockets = $readable_handles->can_write(); #print $sock "You sent $buf\n"; foreach my $sck(@sockets){print $sck "$buf\n";} } else { $readable_handles->remove($sock); close($sock); } } }
This may be a useful implementation, but if you gurus out there could give me the play-by-play on how the code above operates it would help me out tremendously..
Thanks again... more to come...
In reply to Re^2: sockets and such in Perl
by scotchfx
in thread sockets and such in Perl
by scotchfx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |