in reply to Multiplexed TCP-Client (from: Networkprogramming with Perl)
From what I saw, works fine for me (without anything running on localhost:80, it dies with IO::Socket::INET: Timeout)
I don't own lincoln's book.
update: Anyway, check this out
# from perldoc IO::Select, w/sprinkles by me use strict; use warnings; use IO::Select; use IO::Socket; my $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080); my $sel = new IO::Select( $lsn ); my $new; warn "about to enter while"; while(my @ready = $sel->can_read) { warn "in while"; foreach my $fh (@ready) { warn "in foreach"; if($fh == $lsn) { warn "creating a new socket"; # Create a new socket $new = $lsn->accept; $sel->add($new); warn "added new"; } else { warn "processing socket"; warn "read 10 characters and echo them"; read($fh,$_,10); warn "here they are '$_'"; # Process socket # Maybe we have finished with the socket $sel->remove($fh); $fh->close; warn "done with it, neext"; } } } __END__ This is what i got after i ran this script, and then did a\ telnet localhost 8080 hello ther about to enter while at far line 9. in while at far line 11. in foreach at far line 13. creating a new socket at far line 15. added new at far line 19. in while at far line 11. in foreach at far line 13. processing socket at far line 22. read 10 characters and echo them at far line 23. here they are 'hello ther' at far line 25. done with it, neext at far line 30.
____________________________________________________
** The Third rule of perl club is a statement of fact: pod is sexy.
|
|---|