Python socket bind to any IP?

后端 未结 3 1172
Happy的楠姐
Happy的楠姐 2020-12-03 06:49

I have a small one sided message sender that works while I specify the IP to connect to in code, however, I am having trouble allowing the socket to accept connections from

相关标签:
3条回答
  • 2020-12-03 07:20

    Binding to '' has the same effect as to '0.0.0.0' makes the transition to IPv6 easier.

    Depending on the OS, opening a socket.AF_INET6 socket listens to IPv4 and IPv6.

    0 讨论(0)
  • 2020-12-03 07:25

    If you want to bind to all available IPv4 addresses, specify 0.0.0.0 as your IP address. If you're behind a router and wish to have your socket internet-accessible, rather than just available on your LAN, you'll need to set up a port forwarding rule so that users outside your LAN can access the service.

    See the following ServerFault question for more info on 0.0.0.0: https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1

    0 讨论(0)
  • 2020-12-03 07:36

    Binding to 0.0.0.0 will allow it to accept connections from any IPv4 address that can route to it.

    0 讨论(0)
提交回复
热议问题