I have two parts, a client and a server. And I try to send data (size > 5840 Bytes) from the client to the server and then the server sends the data back. I loop this a number o
Two problems that I see:
size
bytes will actually read size
bytes. It does not. TCP is a streaming protocol. A read reads at least one byte. That's the only guarantee given.I'm not sure under what exact circumstances a TCP stack would send a RST. Could be due to the deadlock causing a timeout.
You are not swallowing any exceptions, right?
Normally, closing a connection performs an orderly shutdown in the background. But I'm unsure about what happens when the other side is still writing at this point. Maybe the answer is that an RST is generated by the receiver of the writes. Surely, the TCP spec would answer this question. If this answer is to be trusted then indeed a Shutdown(Read)/Close followed by an incoming write would RST the connection.
Fix both issues and report back with your findings.