[erlang-questions] Socket keepalive option

Per Hedeland <>
Sat Jun 14 12:17:15 CEST 2008

"Greg Burri" <> wrote:
>Is it possible to set the option {keepalive, Boolean} to a socket by
>the server side after the socket has been created ?

I certainly think it should be, but haven't actually verified it.

>I try to do that with an application under Yaws (http://yaws.hyber.org/) :
>out(A) ->
>   inet:setopts(A#arg.clisock, [{active, true}, {keepalive, true}]),
>   [..]
>When the server waits and it doesn't send data I capture the TCP
>stream with Wireshark (http://www.wireshark.org/) and see if there is
>some 'Ack' from the server... but I don't see anything..

Depending on your OS, the timeout for starting keepalive probing is on
the order of a couple of hours, so you need to be patient.:-) E.g.
FreeBSD 7.0:

$ sysctl -a | grep tcp.keep
net.inet.tcp.keepidle: 7200000
net.inet.tcp.keepintvl: 75000
net.inet.tcp.keepinit: 75000


  keepinit     Timeout, in milliseconds, for new, non-established TCP

  keepidle     Amount of time, in milliseconds, that the connection
               must be idle before keepalive probes (if enabled) are

  keepintvl    The interval, in milliseconds, between keepalive
               probes sent to remote machines.  After TCPTV_KEEPCNT
               (default 8) probes are sent, with no response, the
               connection is dropped.

--Per Hedeland

More information about the erlang-questions mailing list