linux - Can an open socket be left for a long time without reading from it? -
i'm opening socket server , sleeping, possibly long time (days). process single-threaded can't have thread dedicated managing socket. socket should stay alive. i'm assuming server not send messages client response required.
the question is, safe assume socket stay alive? linux kernel handle needed tcp communication (e.g. keep-alive packets?) or reading socket required called application time time?
what if server sends messages client? i'm assuming there buffer such data. how big it, how can changed, , happens if full?
in addition has been said here, firewalls , nats may drop tcp connections after period of inactivity. tcp keep-alive messages may not frequent enough keep tcp connections alive. why many application level protocols feature application level keep-alive messages (for example, configure ssh client send keep-alive messages every 30 minutes because office nat drops tcp connections after 1 hour).
in other words, application may exchange messages remote peer once in configurable while.
alternatively, use platform-specific socket option enable tcp keep-alive messages (so_keepalive) , configure timeout (tcp_keepidle on linux).
Comments
Post a Comment