In addition to what BrowserUk said about using our @clients as shared, instead of my @clients; can you put some debugging statements in there to see if control actually gets to the end of the thread and closes the client?
#close filehandle before detached thread dies out print "closing lclient $lclient\n"; close( $lclient); #remove multi-echo-clients from echo list @clients = grep {$_ !~ $lfileno} @clients; print "exiting thread .....clients = @clients\n";

The clients are always connected to the server, except when is some network outage or other gprs disconnections. Then, clients reconnects to the server And there is my problem: Old threads remains connected to the server and I need to get rid of them!

An interesting problem, but it seems that the disconnect should be detected. I wish I had a test setup with many GPS devices to test with.

The first thing that comes to mind, is to keep a hash of connected GPS devices, tracking their id and fileno's, and check for duplicate connections in your server->accept. Another thing is maybe try a different test in your thread for being connected. The connected method returns the address if connected, so maybe you can track addresses, and be sure there are no duplicate addresses?

Maybe try a shorter timeout value? A timeout of 500 is a long time, and may be allowing your device to reconnect before the thread detects the old connection is gone?


I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re: Non closing sockets - threads by zentara
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.