Page 1 of 1

WiFiCLient::availableForWrite() returns 0

Posted: Sat Mar 06, 2021 12:05 pm
by JiPe38
Hello everybody.

I use an ESP32 with the Arduino IDE. In the simple WiFiServer, which instances a WiFiClient for each client connection, I try to see if there is enough room in the TX buffer before sending a complete line. I tried to use availableForWrite () method in order to see if the result is greater than the size of the line that I want to send. But availableForWrite () returns always zero. So... how can I test the available space in the TX buffer ?

Re: WiFiCLient::availableForWrite() returns 0

Posted: Tue May 25, 2021 9:06 am
by JimDrew
I have this same problem as well!

int i = tcpClient.availableForWrite();

This always returns with i equal to 0. This code works perfectly when compiled for the ESP8266.

Re: WiFiCLient::availableForWrite() returns 0

Posted: Sun May 21, 2023 1:20 am
by JimDrew
I have recently run across this exact same issue with a ESP32C3. Code that compiles and works perfectly on the ESP8266 does not work on the ESP32C3 (maybe other ESP32 versions?)

if (tcpClient.availableForWrite() > 0) {
tcpClient.write(sendbuf, sendlength);
}

This skips the write because the result from tcpClient.availableForWrite() is always 0. Again, with a ESP8266 this works perfectly. Any ideas?

If I modify the code to not do the check if data can be sent then my code works, but there is a possibility of over-running the buffer at that point.