I've come across a few limitations of the usocket module regarding UDP and I'm not sure how to handle them.
1. Is there a convenient way to convert the soackaddr struct returned by recvfrom() into a (ip, port) tuple (e.g. for logging)?
Or do I have to use ustruct to parse the struct? How do I convert the in_addr member to the dotted IP address representation then since inet_ntop resp. inet_ntoa are not implemented? Does anyone have or know a pure Python implementation of one of these functions?
(I know I can just pass the binary sockaddr struct to sendto() for replying.)
2. Is there a special reason recvfrom_into() is not implemented?
3. When I was looking at the usocket documention and trying to figure out why
Code: Select all
Only when you look at the getaddrinfo() documentation, you realize that usocket, unlike CPython's socket object, does not take a (host, port) tuple for bind() and connect() but a binary sockaddr structure. I think this should be explicitly mentioned and the misleading sentence quoted above amended. I see that micropython-socket has a convenience function create_connection(), which handles the address conversion automatically. Maybe it would helpful to add this to the connect and bind methods of the socket wrapper in this module as well (for AF_INET sockets)? [Update: ups, sorry, it already does!]