How to keep socket alive?

How to ensure or keep socket alive?

  • Well this is a really open question here "How to ensure or keep socket alive?" I'm afraid that I have to say "sorry" for this open question. But I still wanna ask some ideas. How to provide an end-to-end solution for application, which make application know that both ends works with limited resource? Any solution or suggestion is well appreciated here.

  • Answer:

    I assume you mean a TCP socket. You can't guarantee that it's alive at any given time. If enabling SO_KEEPALIVE does not do what you want, you'll need to do custom keepalive packets within the application protocol. Some protocols, for isntance, have a "NOOP" command which can be used. Under Linux (but not necessarily other OSs) you can modify the keepalive interval used by SO_KEEPALIVE on a per-socket basis (see man 7 tcp)

Daniel at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.