I wrote the following code to listen to a TCP port on a device and simply log it's output. It seems to work fine for about 10-20 hours, but somewhere along the line it just stops, and I can't figure out why. I put the socket timeout all the way up to 604800 sec (7 Days) hoping that it would help, but no luck. I have been using a script to restart the process every hour so it doesn't die on me anymore, but I would like it to just work. Any ideas?

---
use Net::Telnet(); use strict; my ($host, $port, $socket, $line, $filename); $host = $ARGV[0]; $port = $ARGV[1]; $filename = $ARGV[2]; $socket = new Net::Telnet (Telnetmode => 0,Timeout => 604800); $socket->open(Host => $host,Port => $port); for(;;){ $line = $socket->getline; open(LOGFILE, ">>$filename"); print LOGFILE $line; close(LOGFILE); } exit 0;
---

Steve Kamerman
President
HardwareTechNet
www.hardwaretechnet.com

In reply to Problem Keeping Socket Alive by skamerman

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.