Socket connection: Always want to connect, or reconnect when disconnected.

Asked 2 years ago, Updated 2 years ago, 117 views

Thank you for your help.
This is a question about the TCP socket.
In order to ensure response speed, I would like to keep the socket connection connected all the time and reconnect if the connection is disconnected for some reason. Is that possible?Client is Windows 10 C# and server is TBD.
I also want to avoid restarting the server when reconnecting.

c# network socket

2022-09-30 15:02

1 Answers

TCP Keep Alive is well known for keeping connections going as the name suggests.Actually, it can be used not only for that, but also for disconnection detection.
C# can be configured with the Socket.SetSocketOption method.

I also want to avoid restarting the server when reconnecting.

This depends on the server implementation and cannot be controlled by the client.

Is Keep Alive also implemented on Linux?

It is implemented on almost all communication devices, not just Linux.(Otherwise, you will not receive a response, so the moment you enable Keep Alive, you will be disconnected without a response.)


2022-09-30 15:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.