# Client.available() function rerun value is asways 1

**URL:** <https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486>\
**Category:** WiFi\
**Tags:** evb-amb82\
**Created:** [December 2, 2023, 9:27am UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486 "2023-12-02T09:27:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![time4china](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@time4china](https://forum.amebaiot.com/u/time4china)\
**Post date:** [December 2, 2023, 9:27am UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/1 "2023-12-02T09:27:22Z")

</div>

1. AMB82 MINI
2. Arduino SDK (Adruino IDE 2.2.1)
3. The source code is as follows.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/ameba/original/2X/6/6c466615f456172465c0028db3e92b53ee9d853b.png)

1. in ref documents, WiFi - client.available() returns the number of bytes available for reading.  
but in above source code, When connected to the server, availavble() rerurns always 1 regardless of whether the server sends a message or not.  
and When connected to the server, the program doesn’t seem to execute beyond line 37 in the source code. The code beyond line 37 executes only when the connection to the server is terminated.  
(of course, It works correctly on the ESP32 platform with the same source code)

Could you please provide some guidance or advice

---

<div class="post-metadata">

**Author:** ![time4china](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@time4china](https://forum.amebaiot.com/u/time4china)\
**Post date:** [December 5, 2023, 12:59pm UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/2 "2023-12-05T12:59:12Z")

</div>

Dear Realtek

Please check if the source code is wrong or if there is a problem with the available() function

---

<div class="post-metadata">

**Author:** ![Kelvin\_Huang](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kelvin_huang/32/2130_2.png) [@Kelvin\_Huang](https://forum.amebaiot.com/u/Kelvin_Huang)\
**Post date:** [December 6, 2023, 2:55am UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/3 "2023-12-06T02:55:50Z")

</div>

Hi @time4china, please give us some time to troubleshoot this.

Thank you.

---

<div class="post-metadata">

**Author:** ![wdoug](https://avatars.discourse-cdn.com/v4/letter/w/e0b2c6/32.png) [@wdoug](https://forum.amebaiot.com/u/wdoug)\
**Post date:** [December 6, 2023, 11:14pm UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/4 "2023-12-06T23:14:27Z")

</div>

I am experiencing the same problem. Any advice would be appreciated.

---

<div class="post-metadata">

**Author:** ![Kelvin\_Huang](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kelvin_huang/32/2130_2.png) [@Kelvin\_Huang](https://forum.amebaiot.com/u/Kelvin_Huang)\
**Post date:** [December 7, 2023, 5:35am UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/5 "2023-12-07T05:35:39Z")

</div>

Hi @time4china , can you help me test in line 89 of WifiClient.cpp? change return 1 to return ret; with this screenshot here. Let me know if this fix work for you.  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/ameba/original/2X/4/4bd549d7a54cc57869f3972462e5fca9d09796a2.png)

---

<div class="post-metadata">

**Author:** ![time4china](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@time4china](https://forum.amebaiot.com/u/time4china)\
**Post date:** [December 7, 2023, 7:22am UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/6 "2023-12-07T07:22:06Z")

</div>

> [@Kelvin\_Huang](#):
>
> WifiClient.cpp

Dear Kelvin

1. I changed wificlient.cpp as below (return 1 → return ret)  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/ameba/original/2X/a/ac843d7010bd11e0346e41e295191a6d0d4faf56.png)

2. Unfortunately, the result is same as before.  
problem is not solved.

please check again. please

---

<div class="post-metadata">

**Author:** ![Kelvin\_Huang](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kelvin_huang/32/2130_2.png) [@Kelvin\_Huang](https://forum.amebaiot.com/u/Kelvin_Huang)\
**Post date:** [December 7, 2023, 8:24am UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/7 "2023-12-07T08:24:15Z")

</div>

Hi @time4china, my bad, give me some more time to debug. thanks

---

<div class="post-metadata">

**Author:** ![Kelvin\_Huang](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kelvin_huang/32/2130_2.png) [@Kelvin\_Huang](https://forum.amebaiot.com/u/Kelvin_Huang)\
**Post date:** [December 7, 2023, 9:14am UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/8 "2023-12-07T09:14:01Z")

</div>

Hi @time4china,

When you create the WiFiClient, can you set non blocking mode and test again?

WiFiClient client(NON\_BLOCKING\_MODE);

---

<div class="post-metadata">

**Author:** ![time4china](https://avatars.discourse-cdn.com/v4/letter/t/3d9bf3/32.png) [@time4china](https://forum.amebaiot.com/u/time4china)\
**Post date:** [December 7, 2023, 10:13am UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/9 "2023-12-07T10:13:15Z")

</div>

> [@Kelvin\_Huang](#):
>
> NON\_BLOCKING\_MODE

after setting WiFiClient client(NON\_BLOCKING\_MODE);

problem is solved,

thank you very much.

---

<div class="post-metadata">

**Author:** ![wdoug](https://avatars.discourse-cdn.com/v4/letter/w/e0b2c6/32.png) [@wdoug](https://forum.amebaiot.com/u/wdoug)\
**Post date:** [December 8, 2023, 3:04am UTC](https://forum.amebaiot.com/t/client-available-function-rerun-value-is-asways-1/2486/10 "2023-12-08T03:04:21Z")

</div>

Proposed solutions did not work for me.  
I commented out line 93 and it works.
