-
I'm trying to create an SSL connection from an ESP32 to a server using a non-blocking socket. Maybe I'm misunderstanding something, but I can't get it to work with deferred handshake...
Based on the documentation, I expected the SSL handshake to happen when I called the If I instead change Am I missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi |
Beta Was this translation helpful? Give feedback.
-
The asyncio code supports non-blocking SSL connections: https://github.com/micropython/micropython/blob/master/extmod/asyncio/stream.py#L99-L123 You might need to set the socket to non blocking before connecting the socket. Also be aware that a read/write to a non-blocking SSL socket may return without finishing, by virtue of being non-blocking. So keep reading/writing until it does go through. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much! That works perfectly for my application. One question - does closing the wrapped SSL socket also close the underlying socket? Or is extra cleanup required there? |
Beta Was this translation helpful? Give feedback.
That's actually the correct behaviour, because it's a non-blocking connect the call to
s.connect()
will return immediately and the connection will happen in the background.Yes, actually, that's what you need to do. The return value tells you how much was written, and you must try to write the remaining data again.
Here's some non-blocking SSL code that works for me (when run on the unix port of MicroPython):