CompleteMoron has asked for the wisdom of the Perl Monks concerning the following question:
I have allready anticipated another problem I will have. As you see, it accepts any new sockets, but what if, I want to send data to all open sockets the server has received? I see no where (array, etc) where the sockets are saved. Any help?#!/usr/bin/perl #test script use IO::Socket; use IO::Select; if(@ARGV < 1) { printf("Usage:\ntest.pl <port to run on>\n"); exit(); } my $sock = IO::Socket::INET->new( Proto=>"tcp", LocalHost=>"Localhost", Listen=>16, Reuse=>1, LocalPort=>$ARGV[0] ) or die("Could not create socket!\n") +; my $readSet = new IO::Select(); $readSet->add($sock); while(1) { my $rhSet = IO::Select->select($readSet, undef, undef, 0); foreach $rh(@rhSet) { if($rh == $sock) { $newSocket=$rh->accept(); $readSet->add($newSocket); } else { $buf=<$rh>; if($buf) { printf "$buf"; } else { $readSet->remove($rh); close($rh); } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: New to perl: IO Select question :(
by Roger (Parson) on Aug 21, 2005 at 00:00 UTC | |
by pg (Canon) on Aug 21, 2005 at 00:38 UTC | |
by CompleteMoron (Initiate) on Aug 21, 2005 at 00:10 UTC | |
by Roger (Parson) on Aug 21, 2005 at 00:16 UTC | |
by CompleteMoron (Initiate) on Aug 21, 2005 at 00:20 UTC | |
by Roger (Parson) on Aug 21, 2005 at 00:34 UTC | |
|
Re: New to perl: IO Select question :(
by pg (Canon) on Aug 21, 2005 at 00:32 UTC | |
by Crackers2 (Parson) on Aug 21, 2005 at 03:17 UTC | |
by pg (Canon) on Aug 21, 2005 at 03:50 UTC | |
by Bob9000 (Scribe) on Aug 21, 2005 at 05:02 UTC | |
|
Re: New to perl: IO Select question :(
by zentara (Cardinal) on Aug 21, 2005 at 12:39 UTC |