skip to Main Content

I got a server running on 0.0.0.0:18830.
On windows when I trying to connect to this server with python socket

socket.connect_ex('0.0.0.0', 18830)

it returns 10049

with the following code

socket.connect_ex('127.0.0.1', 18830)

it returns 0 which means ok

However when I run the server and the two codes above on WSL Debian
Both commands will return 0

Any explains on why it happens like this?

2

Answers


  1. 127.0.0.1 is the loopback address (also known as localhost) and 0.0.0.0 is the IP address that is a non-routable meta-address used to indicate an invalid, unknown, or non-applicable destination.

    0.0.0.0 and 127.0.0.1 are easy to confuse, but let’s keep remember that an address with four zeros has a few defined uses, whereas 127.0.0.1 instead has the very specific purpose of allowing a device to send messages to itself.

    0.0.0.0 could be used to mean anything that accepts all IP addresses or blocks all IP addresses to the default route, and sometimes referred to as a wildcard address, unspecified address, or INADDR_ANY .

    Login or Signup to reply.
  2. The first part of this answer, up to the horizontal line, is looking from the server’s point of view, a.k.a. the service’s point of view.

    When you provide a service on 0.0.0.0 that means it binds to all interfaces – so if your computer has 2 wired Ethernet cards and one wifi interface, the service will be accessible to any client/device on any of those networks.

    When you provide a service on 127.0.0.1 it will only be available to clients running within the same machine it is running on.

    In essence, 0.0.0.0 means "anywhere and everywhere", while 127.0.0.1 means "precisely here and nowhere else".


    Let’s look now from the point of view of a client which is trying to connect to a service.

    If the client tries to connect to 127.0.0.1, it means it is looking for a server running on the same machine as itself.

    If the client tries to connect to 0.0.0.0 that isn’t specific enough to be successful – do you mean a lovely, quality-assured service in your main office, or some grubby, malware server in a far-flung, law-less country?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search