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.


In reply to Re^7: Non closing sockets - threads by gone2015
in thread Non closing sockets - threads by igor1212

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.