0

I am facing issue of not receiving error in return of "send()" function in case of TCP socket disconnected at client side. I am using example TCP server(ESP32C3) by using LwIP stack (version v2.1.3). To debug this issue I have added delay of 50ms after sending data and then send same data again on same socket then I am getting error of -14 which is as expected . I have modified default TCP server example which is given by ESP-IDF to send 256 bytes continuously.

Any specific time and function for which we need to wait and then check for ACK/NACK from TCP socket of packet which server sent to client?

            while (to_write > 0)
            {
                vTaskDelay(20000 / portTICK_PERIOD_MS); // disconnecting TCP client manually (Hercules.exe)

                int written = send(sock, rx_buffer + (len - to_write), 256, 0);
                vTaskDelay(50 / portTICK_PERIOD_MS);
                written = send(sock, rx_buffer + (len - to_write), 256, 0);
                if (written < 0)
                {
                    ESP_LOGE(TAG, "Error occurred during sending: errno %d", errno);
                }

                ESP_LOGE(TAG, "Error occurred during sending: errno %d", errno); // not getting error 1st time
                errno = 0;
                to_write -= written;
            }

I have disabled nagle's algorithm .

        int val = true;
        if (!(setsockopt(sock_internal, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(int)) == ESP_OK))
        {
            ESP_LOGE(TAG, "failed to set tcp no delay");
        }
craval
  • 1

0 Answers0