fumin
fumin

Reputation: 33

How to fix WSAECONNABORTED error?

I have a C/S application. The client usually send a large amount of data to server using TCP protocol. It works well in LAN environment(10MB/s), but network errors happen when I migrate it to WAN environment(200KB/s).

As I track the bug, I find that send() in client returns -1 and WSAGetLastError() returns WSAECONNABORTED at first; And several seconds later, recv() in server also returns -1 and errno is ECONNRESET.

After consulting documents, I have a basic understanding of WSAECONNABORTED and ECONNRESET. I think the former is resulted from the bad network: TCP closes the socket after several retransmission failures. And the latter is resulted from the unexpected close operation in client.

I wonder how to handle this kind of error. Reconnect immediately? Or any socket options can help?

Upvotes: 3

Views: 12383

Answers (1)

user207421
user207421

Reputation: 310893

You are correct.

The former results from network problems. All you can do is try again with a new socket.

The latter is an application protocol error. You're sending while the peer has already closed. This is an application bug. The cure is to fix the bug.

Upvotes: 2

Related Questions