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

If one end simply stops sending packets (including closing its end without sending a 'FIN') the other end will wait pretty much indefinitely. (I have tried this with a server running on Linux and Windows XP -- Perl 5.10.0.)

Could tell me how, on XP, you can drop the connection between this server:

#! perl -slw use strict; use IO::Socket; my $server = new IO::Socket::INET( Timeout => 500, Proto => "tcp", LocalPort => 54321, Reuse => 1, Listen => 5 ) or die $^E; my $client = $server->accept; print while <$client>; print "client went away";

and this client:

#! perl -slw use strict; use IO::Socket; my $con = IO::Socket::INET->new( 'localhost:54321' ); print $con "ping" while sleep 1; print "client ended";

Without the server noticing?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^7: Non closing sockets - threads
by gone2015 (Deacon) on Dec 16, 2008 at 23:40 UTC

    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.