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

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
kkumar326
Posts: 16
Joined: Wed Nov 15, 2017 5:30 am

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

Post by kkumar326 » Fri Feb 09, 2018 8:17 am

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.

User avatar
pythoncoder
Posts: 4658
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Fri Feb 09, 2018 10:10 am

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.
Peter Hinch

kkumar326
Posts: 16
Joined: Wed Nov 15, 2017 5:30 am

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

Post by kkumar326 » Fri Feb 09, 2018 12:02 pm

Thanks for the link. It's working now :)

Post Reply