> -----Original Message----- > From: Daniel Gardner [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, October 17, 2001 6:50 PM > To: [EMAIL PROTECTED] > Subject: socket closed > > > Hi, > > i have code that looks something like this: > > my $sock = IO::Socket::INET->new(%args); > my $sel = new IO::Select $sock; > while (1) { > my @ready = IO::Select->can_read(1); > foreach my $socket (@ready) { > # read a line > my $line = <$socket>; > > &do_stuff_with_line($line); > } # end foreach > > # do other stuff > } # end while > > which works just great, except for when the remote server closes the > connection on the socket i've opened. IO::Select seems to return the > handle as being ready to read from, and <$socket> > immediately returns > undef. > > so my question is, how do i tell if the remote server has closed the > connection?
That's how you tell. when <$socket> returns undef, that means you've hit end of file, which on a socket means the other end has closed. At that point, just break out of your loop. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]