nomem
nomem

Reputation: 1588

persistent tcp socket connection in c

I have a C service application that use tcp socket for connection to a server. The server sends data now and then. Also my application sends a hearbeat every 15 seconds. But sometimes it disconnects while server seems to think the connection is live. Now if I try to reconnect the server refuses as it holds only one connection for the client at a time.

What is the best way to hold a persistent tcp connection?

Edit: The server usually disconnects after 2 min without heartbeat. So after I find my connection is closed it takes 2min for me to successfully reconnect. I want to minimize this time.

Upvotes: 1

Views: 1135

Answers (1)

David Schwartz
David Schwartz

Reputation: 182763

The simplest fix is probably for the server to allow a new connection to replace an old connection rather than rejecting it. That would still keep only one connection to each client at a time.

Upvotes: 1

Related Questions