Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep tcp connection alive #249

Closed
albosmart-ro opened this issue Sep 10, 2020 · 2 comments
Closed

Keep tcp connection alive #249

albosmart-ro opened this issue Sep 10, 2020 · 2 comments
Labels

Comments

@albosmart-ro
Copy link

How do i keep the tcp connection alive?

@WyriHaximus
Copy link
Member

You don't have to, TCP connections stay connected as long as nothing between both peers puts a timeout on it. You can send a heartbeat over it every X seconds to ensure it is still alive. But aside from that it should just stay connected

@clue clue added the question label Sep 14, 2020
@clue
Copy link
Member

clue commented Sep 14, 2020

What @WyriHaximus said :-)

TCP/IP connections will be kept alive until one side decides to close the connection. It's perfectly fine to not transmit anything over an idle connection for hours or even days (YMMV).

Note that depending on your network setup, you may have a number of middleboxes between both connection endpoints which may limit the lifetime of a connection. Many load balancers or NAT devices are known to terminate idle connections after a while, a timeout of 60 or 600 seconds is quite common.

If you're experiencing timeouts, you may want to occasionally transmit some data over the connection to keep it alive. Many protocols provide some mechanisms (framing) to support keep-alive or heartbeat messages.

In many cases, closing idle connections can be considered a good thing as it allows freeing up some resources.

I hope this helps 👍

@clue clue closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants