What is the difference in listening to "0.0.0.0:80" and ": 80"?

When we use http.ListenAndServe, what is the difference between:

http.ListenAndServe("0.0.0.0:80", nil)

and

http.ListenAndServe(":80", nil)

? Will both versions be tapped on all interfaces on the port 80?

+4
source share
1 answer

The function http.ListenAndServe()ultimately calls net.Listen(). The documentation for net.Listenstates that it will be tied to the network provided to it:

For TCP networks, if the host in the address parameter is empty or an odd undefined IP address, Listen listens on all available unicast and anycast IP addresses of the local system. To use only IPv4, use the "tcp4" network.

, http.ListenAndServe(), , "tcp" , "tcp4", , . , golang, internetAddrList(), , host , ipv4. , golang infact, ipv4, .

+5

Source: https://habr.com/ru/post/1694346/


All Articles