Page 1 of 1

How to send/ receive data through socket in Non-Blocking mode?

Posted: Fri Feb 09, 2018 8:17 am
by kkumar326
In documentation, it is written that non-blocking just sets the timeout to 0 seconds
sock.setblocking(False) is equivalent to sock.settimeout(0)
and thus it's not possible to get or send data. Is there some hack or workaround to get both of these things done simultaneously?

I'm working on ESP8266.

Re: How to send/ receive data through socket in Non-Blocking mode?

Posted: Fri Feb 09, 2018 10:10 am
by pythoncoder
I suggest you look at the MQTT_base._as_read() and MQTT_base._as_write() methods here. There is some cruft there to deal with ESP32 weirdness which is unnecessary on the ESP8266, e.g. the esp32_pause() function which is null on ESP8266. But hopefully the code will suggest the general approach.

Re: How to send/ receive data through socket in Non-Blocking mode?

Posted: Fri Feb 09, 2018 12:02 pm
by kkumar326
Thanks for the link. It's working now :)