W5100 send SOCKERR_SOCKSTATUS after few success writes

Hi All,

I am using w5100 Ethernet shield with STM32L476 Nucleo board.
I have following flow which fails at 5th operation, Can anyone help in figuring out what could be wrong in my operation.

1. Create Socket
socketNumber = socket(0, Sn_MR_TCP, portNo, SF_TCP_NODELAY);
socket() created socket number = 0
socket create return val = 1

2. Send data on Socket
socket number = 0 & numBytesToWrite = 132
retValue = send(socketNumber, (uint8_t *)pBuffer, numBytesToWrite);
send retValue = 132

3. Read data on Socket
socket number = 0 & maxBytesToRead = 2048
retValue = recv(socket, (uint8_t *)pBuffer, maxBytesToRead);
read bytes retValue = 1950

4. Send data on Socket
socket number = 0 & numBytesToWrite = 267
retValue = send(socketNumber, (uint8_t *)pBuffer, numBytesToWrite);
send retValue = 267

5. Send data on Socket
socket number = 0 & numBytesToWrite = 6
retValue = send(socketNumber, (uint8_t *)pBuffer, numBytesToWrite);
send retValue = -7

#define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7) ///< Invalid socket status for socket operation.

What could be that it is returning SOCKERR_SOCKSTATUS error.

Best regards,
Sachin

When error occurs please read Sn_SR register to identify which status socket is in.

Hi Eugeny,

Thanks for reply.

After write failure I tried to read Sn_SR register it gave following value.

  1. Send data on Socket
    socket number = 0 & numBytesToWrite = 6
    retValue = send(socketNumber, (uint8_t *)pBuffer, numBytesToWrite);
    send retValue = -7

Sn_SR(socket) retValue = 1027

Best regards,
Sachin

Sorry for inconvenience.

Previously, I just gave you #define for Sn_SR(socket) As it is 0x403

Now I just checked
retValue = getSn_SR(socket);
retValue = 0

So for some reason socket is being closed when you try to send more data.
I can only guess what is going on; for example, if you use HTTP protocol, you may be sending wrong data during your step 4, and remote host closes the connection.
I propose you looking at what is going on the network using Wireshark to see what is actually being sent, and check the sequence of packets.
If you wish you can capture network activity log using Wireshark, and share it here so that we can have a look.

Thank you Eugeny for reply.

Finally I tried with local server on machine and send request from board and found that my processing take time so server timeout and close socket.

I have increased server read timeout and it worked. I need to process my data ASAP so server will not give timeout.

By the way I have not found blocking flag for 5100 while creating socket.

How to implement blocking send or connect request.

Please explain. What you want to achieve?

Currently I don’t have any blocker, as my application has lot of transaction with multiple socket on server so I was thinking to have each transaction in blocking mode which can confirm each operation done synchronously.

I can see that other chips like 5500 has flag SF_IPv6_BLOCK so thought if needed to 5100 then how I can implement same.

What is “blocking mode” in your understanding? Please explain what you want to achieve (not how you think you can achieve something).

synchronous write/read for large data in range of 20KB.