swiftone has asked for the wisdom of the Perl Monks concerning the following question:
I've been reading through Chapter 12 of the panther book, and I'm looking at the following code:
My questions are:use IO::Socket; use IO::Select; $main_socket = new IO::Socket::INET (LocalHost => 'localhost', LocalPort => 1200, Listen => 5, Proto => tcp, Reuse => 1); die "Socket not created: $!\n" unless ($main_socket); $readable_handles = new IO::Select(); $readable_handles->add($main_socket); while(1){ #select() blocks until a socket is ready to be read ($new_readable) = IO::Select->select($readable_handles,undef,undef +,0); #We now have at least one readable handle. foreach $sock (@$new_readable){ if ($sock == $main_socket){ $new_sock = $sock->accept(); #new connection, add to list. #May not be readable yet. $readable_handles->add($new_sock); } else { #check to see if socket closed $buf = <$sock>; if($buf) { #Do stuff with $buf } else { #socket was closed $readable_handles->remove($sock); close($sock); } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jcwren) Multiple clients with IO::Sockets, IO::Select
by jcwren (Prior) on Sep 08, 2000 at 18:53 UTC | |
|
Re: Multiple clients with IO::Sockets
by merlyn (Sage) on Sep 08, 2000 at 18:46 UTC | |
|
Re: Multiple clients with IO::Sockets
by Fastolfe (Vicar) on Sep 08, 2000 at 18:48 UTC | |
|
Re (tilly) 1: Multiple clients with IO::Sockets
by tilly (Archbishop) on Sep 08, 2000 at 20:05 UTC | |
by swiftone (Curate) on Sep 08, 2000 at 20:16 UTC | |
by tilly (Archbishop) on Sep 08, 2000 at 20:26 UTC |