Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

socket.connect and socket.bind getaddrinfo behaviour is not CPython compliant #5

@dpgeorge

Description

@dpgeorge
  • On the esp8266 you need to call socket.getaddrinfo() to get the IP
    address you want to bind/connect with. Then the result of this call
    is fed into bind/connect. In that case, bind/connect don't call
    getaddrinfo but rather just take a raw IP address and port (as an
    integer) and use that. This is also compatible with CPython. But as
    a convenience CPython also allows you to pass a domain name instead of
    an IP address to bind/connect, and in that case it'll do a getaddrinfo
    for you. You can look at extmod/modlwip.c to see how it's done there
    (eg it uses netutils_parse_inet_addr). But it should be that at least
    I can use the following 2 ways to connect (or bind):

s=socket.socket()
s.connect(('176.58.119.26', 80)) # specify IP address and port directly

s=socket.socket()
ai=socket.getaddrinfo('micropython.org', 80) # lookup domain
s.connect(ai[0][-1])

The above works on CPython, unix-MicroPython and esp8266-MicroPython.

[Nick filled this in from a previous Damien email]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions