[issue17561] Add socket.bind_socket() convenience function

Giampaolo Rodola' report at bugs.python.org
Mon Apr 8 18:39:30 EDT 2019


Giampaolo Rodola' <g.rodola at gmail.com> added the comment:

Patch committed as of:
https://github.com/python/cpython/commit/eb7e29f2a9d075accc1ab3faf3612ac44f5e2183
For posterity, since the API evolved since the original proposal (as per PR review/suggestions), this is the final incarnation:

    # IPv4 only
    >>> socket.create_server(addr)  
    # IPv6 only
    >>> socket.create_server(addr, family=socket.AF_INET6)
    # IPv4 + IPv6
    >>> socket.create_server(addr, family=socket.AF_INET6, dualstack_ipv6=True)
    # IPv4/6 if possible and don't care about IPv4 mapped addresses, else IPv4
    >>> if socket.has_dualstack_ipv6():
    ...    s = socket.create_server(addr, family=socket.AF_INET6, dualstack_ipv6=True)
    ... else:
    ...    s = socket.create_server(addr)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue17561>
_______________________________________


More information about the Python-bugs-list mailing list