Thanks for the reply! Let me ask a different question…
Would this code work OK?
uint socketStatus = w5500.readSnSR(sock);
if (socketStatus != SnSR::LISTEN)
// 1) this might read RX_RS on a closed socket but thats OK, right?
// 2) a closed socket might have data in the buffer that still needs to be read
if (w5500.getRXReceivedSize(sock) > 0)
if (socketStatus == SnSR::CLOSED)
RecreateSocket(sock); // change the socket back to LISTEN
The idea is that a socket can be established, close_wait, closed, or any other status and still have data in the receive buffer. The only time I know a receive buffer is empty is when I re-create (LISTEN) on the socket.
Would the above code work OK in a loop or is that incorrect?
My application is a TCP server that receives small commands and executes them. If a client connects, sends a command, and then disconnects I still want to process the command which is why I care about data even on closed sockets.