Post topics, source code that relate to the Arduino Platform

User avatar
By Seb.26
#67285 Hi world,

I have an ESP-12 that stay awake to do some background jobs, but I turn WIFI OFF when not needed.

Periodically I turn WIFI ON, connect to WIFI AP, open TCP socket and send/receive some data from a server, and when this is done, I turn WIFI OFF.

My problem is : how do I know that all data I've sent have been received by the server ?

For exemple, if I turn WIFI OFF just after the data sending, the server don't receive last bytes, looks like I've switch OFF WIFI before the TCP job is done.

So I've add a "delay(5000)" and all is fine, but this is not a great solution :
> 5000ms is probably far too long 95% of time
> 5000ms will be too short a day with bad WIFI or busy server or ... ?!

So : how can I check that TCP socket have finish to send data ?

Thanks.
User avatar
By Seb.26
#67307 Thanks for your answer.

The Arduino doc says :
Whether or not the client is connected. Note that a client is considered connected if the connection has been closed but there is still unread data.


So the .connected() flag will wait the socket is "really" close before go false, this sounds great ! ;)

I will try that asap, thanks !