WiFiCLient::availableForWrite() returns 0

JiPe38
Posts: 1
Joined: Sat Mar 06, 2021 11:19 am

WiFiCLient::availableForWrite() returns 0

Postby JiPe38 » Sat Mar 06, 2021 12:05 pm

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 ?

JimDrew
Posts: 7
Joined: Sun Jun 14, 2020 10:28 pm

Re: WiFiCLient::availableForWrite() returns 0

Postby JimDrew » Tue May 25, 2021 9:06 am

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.

JimDrew
Posts: 7
Joined: Sun Jun 14, 2020 10:28 pm

Re: WiFiCLient::availableForWrite() returns 0

Postby JimDrew » Sun May 21, 2023 1:20 am

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.

Who is online

Users browsing this forum: Google [Bot] and 32 guests