0

I was just trying SSL-Sockets in Micropython and discovered that I can not set the connection to non-blocking as the setblocking() function is not implemented, yet.

>>> import ussl
>>> import usocket
>>> s = usocket.socket()
>>> adr = usocket.getaddrinfo('myserverwithssl.com', 443)[0][-1]
>>> s.connect(adr)
>>> s_ssl = ussl.wrap_socket(adr)
>>> s_ssl.setblocking(False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NotImplementedError:

Looking forward to the implementation. However, is there another way to achieve nonblocking SSL-Sockets in Micropython?

MrLeeh
  • 5,321
  • 6
  • 33
  • 51
  • Never worked with _Micropython_, but shouldn't you call `setblocking` on `s` rather than `s_ssl`? – CristiFati Apr 21 '17 at 11:22
  • @CristiFati I tried this. It is not working. A `s_ssl.read()` will still block. Even on CPython you need to use the `setblocking` method of the SSLSocket object otherwise you will get a `ValueError: do_handshake_on_connect should not be specified for non-blocking sockets` – MrLeeh Apr 21 '17 at 11:46
  • It seems this was recently merged: https://github.com/micropython/micropython/pull/3226 – Hiway Aug 08 '17 at 18:28
  • That's great news. I'll give it a try asap. Thanks for letting me know. – MrLeeh Aug 08 '17 at 19:28

0 Answers0