title: How to use SO_KEEPALIVE option properly to detect that the client at the other end is down?
body: <p>I was trying to learn the usage of option SO_KEEPALIVE in socket programming in C language under Linux environment.</p>
  <p>I created a server socket and used my browser to connect to it. It was successful and I was able to read the GET request, but I got stuck on the usage of SO_KEEPALIVE.</p>
  <p>I checked this link <a href="http://tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/" rel="nofollow noreferrer">keepalive_description@tldg.org </a> but I could not find any example which shows how to use it.</p>
  <p>As soon as I detect the client's request on <code>accept()</code> function I set the <code>SO_KEEPALIVE</code> option value <code>1</code> on the client socket. Now I don't know, how to check if the client is down, how to change the time interval between the probes sent etc.</p>
  <p>I mean, how will I get the signal that the client is down? (Without reading or writing at the client - I thought I will get some signal when probes are not replied back from client), how should I program it after setting the option SO_KEEPALIVE on).</p>
  <p>Also if suppose the probes are sent every 3 secs and the client goes down in between I will not get to know that client is down and I may get SIGPIPE.</p>
  <p>Anyways importantly I wanna know how to use SO_KEEPALIVE in the code.</p>