Hi,

some time ago I asked similar question. Now I got some clues how to do this properly, but I can't find any decent docs or tutorials on this matter in Perl.

I want to write TCP client, that will automatically maintaint TCP socket to server and reconnect if necessary...

I got following sockopt options to use:

#KeepAlive<br> setsockopt($sck,SOL_SOCKET, SO_KEEPALIVE, pack("l", 1)); <br> #After 30 secs idle send KeepAlive probe<br> setsockopt($sck,IPPROTO_TCP,TCP_KEEPIDLE, pack("l", 30)); <br> #Rest probes after 30 secs.<br> setsockopt($sck,IPPROTO_TCP,TCP_KEEPINTVL,pack("l", 30)); <br><br>
Now I have no clue how to include this in Perl program - do I have to write in event-driven manner or just collect state of socket in ordinary manner. I'd just like a program that will reconnect/maintain socket connection (with those socket options)and will not loose data sent to tcp connection - will continue only if write was succesful and rewrite on broken socket ...

I'd kindly ask for more info, pointers or working examples....

Thanks in advance,

Rob.

In reply to maintain tcp socket by Anonymous Monk

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.