in reply to New to perl: IO Select question :(

I think the most likely problem in your code is here:
my $rhSet = IO::Select->select($readSet, undef, undef, 0); foreach $rh(@rhSet) {
Should it be my @rhSet = ...? Your @rshSet was never set in your script. It's a common error for new Perl programmers. You can catch these kinds of errors if you turn on the strict pragma with use strict; at the top of your code.

I recommend to use the cpan module Net::Server to write your server. Unless you are learning socket level programming, why bother with low level stuff when you have a well written module that does pretty much everything you want?

Replies are listed 'Best First'.
Re^2: New to perl: IO Select question :(
by pg (Canon) on Aug 21, 2005 at 00:38 UTC

    His code will never accept any connection, thus never enter the while loop. Without fixing that, but only focus on issues inside the while loop will not make his code work.

Re^2: New to perl: IO Select question :(
by CompleteMoron (Initiate) on Aug 21, 2005 at 00:10 UTC
    Thanks for the reply. Making it an array (@) still doesnt make a difference :( Yeh when I was reading a perl tutorial they mentioned that all variables must be declared with a "my" infront of them, but then reading the select() tutorial, some variables used my, some didnt so that confused me, I just copied the code. Any more suggestions? **EDIT** Yes, i am learning network programming, but il take a look at net::server thanks
      Try this instead, in case the select method returns a reference to an array:
      my $rhSet = IO::Select->select($readSet, undef, undef, 0); foreach $rh(@$rhSet) {

      You should also read the perldoc for IO::Select, there is a short example at the end.
      perldoc IO::Select EXAMPLE Here is a short example which shows how "IO::Select" could be used to write a server which communicates with several sockets while also listening for more connections on a listen socket use IO::Select; use IO::Socket; $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080); $sel = new IO::Select( $lsn ); while(@ready = $sel->can_read) { foreach $fh (@ready) { if($fh == $lsn) { # Create a new socket $new = $lsn->accept; $sel->add($new); } else { # Process socket # Maybe we have finished with the socket $sel->remove($fh); $fh->close; } } }

        Yup I'v seen that example, and tried it with can_read aswell, same thing happens :(