in reply to Re^6: Non closing sockets - threads
in thread Non closing sockets - threads

Try moving the client to a different machine. I used:

#! perl -w use strict; use IO::Socket; my $host = $ARGV[0] ; $|++ ; my $con = IO::Socket::INET->new( "$host\:54321" ) or die "failed to c +onnect: $!" ; while (print $con "ping\n") { print "*" ; sleep 1 ; } ; print "client ended: $!\n";
Set the two ends going. Disconnect the client machine from whatever network connects them. After a while, the client will give up. The server won't. (You can get the same effect by pulling the plug on the client machine, but I wouldn't recommend that.)

As far as the server is concerned, this is related to changing the your client to:

use strict ; use IO::Socket ; $|++ ; my $con = IO::Socket::INET->new( 'localhost:54321' ) or die "failed to + connect: $!" ; for (1..20) { print $con "ping\n" ; print "*" ; sleep 1 ; } ; print " client hanging" ; while (1) { print "." ; sleep 60 ; } ;
except that when you finally get bored and terminate the client, the OS will close the client end of the connection and the server will get to hear about it.