the socket rabbit hole

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

the socket rabbit hole

Post by KJM » Mon Apr 25, 2022 3:20 am

I've tended to use urequests or variants of it for for server connections but I've never been really happy with it. There are some overly long non user adjustable timeouts baked into it & the DNS lookups can be cranky on lte based bearers.

Many examples of connecting to servers tend not to use urequests & show examples based simply on sockets. I tend to disregard them because they don't use ssl. Recently a Freenove example

Code: Select all

connectWifi(ssidRouter,passwordRouter)
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect((host,port))
used the socket.SO_REUSEADDR cmd. This was new to me https://stackoverflow.com/questions/322 ... tion-linux & got me wondering how these non urequests based connections convert the server name to an ip address since there is no obvious DNS lookup? Can anyone enlighten me?

Microprofessor
Posts: 5
Joined: Mon Feb 28, 2022 5:56 pm

Re: the socket rabbit hole

Post by Microprofessor » Sun May 01, 2022 8:54 pm

I think I feel your pain :)

I've been trying to get sockets to work the last few days, and it's still a mystery to me. Sorry I can't help you.
The problem I'm currently running into is:

self.serv_soc.setsockopt(usocket.SOL_SOCKET, usocket.SO_REUSEADDR, 1)

AttributeError: 'module' object has no attribute 'SOL_SOCKET'

User avatar
Roberthh
Posts: 3668
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: the socket rabbit hole

Post by Roberthh » Mon May 02, 2022 5:49 am

Socket support is incomplete on some ports like rp2040 nano connect. Other ports like the ESP32 or ESP8266 and Pyboard have better coverage.

Post Reply