localhost
(127.0.0.1
) is so Powerful~16.7 million reserved IP addresses that every device has.
Localhost is 127.0.0.0/8
, which means the number of usable hosts is 16,777,214
. Each IP address has 65535 ports (less in practice since some ports are reserved, and other used for common applications). This means that a web server running on 127.0.0.1:9001
does not conflict with a web server running on 127.0.0.2:9001
, or 127.0.1.1:9001
, or 127.1.1.1:9001
, and so on.
I encourage you to test out what I said above with the simple Go web server below.
package main
import (
"log"
"net/http"
)
func main() {
.HandlerFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Fprintf(w, "hello, world!")
fmt})
// Change `127.0.0.1` to `127.0.1.1` in a copy and run it as well
.Fatal(http.ListenAndServe("127.0.0.1:9001", nil))
log}
Related:
Tags:
#localhost #networking #go