The phone's address is not yours
0.0.0.0 vs 127.0.0.1. http://192.168.x.x:8000 on a second device.
You will be able to
- Explain why
http://localhost:8000fails on the phone but works on the laptop —127.0.0.1means this machine only. - Say what
0.0.0.0means as a bind address versus127.0.0.1, and confirm from the server banner which onepython3 -m http.serveruses. - Open
http://192.168.x.x:8000on a second device on the same Wi-Fi.
The laptop tab still shows your page.
http://localhost:8000 works there.
Pick the phone up. Type the same URL again.
It fails. Same letters. A different machine.
localhost is not a shared name for the laptop.
It is the machine that is asking.
The phone asked itself.
Its browser looked for a server on the phone.
Nothing on the phone is serving ~/projects/first-site.
The name that never leaves
localhost and 127.0.0.1 name the same kind of address.
127.0.0.1 is loopback.
Loopback is this computer talking to itself.
Loopback must not appear outside a host.
The phone cannot use the laptop’s loopback.
It has its own 127.0.0.1.
That address never leaves the phone either.
That is why the laptop tab works and the phone does not. The laptop asked itself, and the server is there. The phone asked itself, and the server is not.
People type localhost from another device because it already worked once.
The name did not travel with you.
It never meant “the laptop”.
It meant “me”.
All doors were already open
The server should still be running in ~/projects/first-site.
If the terminal is gone, start it again:
python3 -m http.server 8000
Look at the first line it printed. That line is the banner — the server saying where it listens.
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Click any piece of the line the server printed.
Serving HTTP0.0.0.08000http://0.0.0.0:8000/0.0.0.0 on the phone.0.0.0.0 is where the server listens. It is not the address the phone types.A bind address is the address the server listens on.
0.0.0.0 means all interfaces.
Every address this machine has is a door the server will answer.
The number you wrote down in Unit 3 is one of those doors.
127.0.0.1 as a bind would mean this machine only.
--bind 127.0.0.1 is how you ask for that.
You did not type that flag.
The default is all interfaces.
The banner already said so.
Read the word after on.
It is 0.0.0.0, not 127.0.0.1.
You do not restart the server with a new flag. The server was willing. The URL was not.
Do not type http://0.0.0.0:8000 on the phone.
0.0.0.0 is a listen address, not a place the phone can visit.
Type the third address
You wrote a LAN IP down in Unit 3.
A LAN is the machines that share your Wi-Fi.
That number is the laptop on this network.
If the scrap is gone, run ip -4 addr again.
Skip the 127.0.0.1 line.
Write the other number.
On the phone, type http://, then that number, then :8000.
Both devices must be on the same Wi-Fi. Mobile data is a different network. A phone on mobile data cannot see a private LAN address.
Open it.
The same index.html should appear.
The phone sent the request to the laptop this time.
Same file.
A third address.
Look back at the terminal.
A new line appears when the phone asks. That line is an access log — the server’s record of who asked.
The first field is the client.
Reload the laptop tab.
That new line starts with 127.0.0.1.
The laptop asked itself again.
Reload the phone.
The next line starts with a different address.
That address is the phone.
It is not 127.0.0.1.
Do not guess the number. Read the one the server just printed. The different first field is the proof the second device arrived.
http://localhost:8000 on the laptop | http://localhost:8000 on the phone | http://192.168.x.x:8000 on the phone | |
|---|---|---|---|
| Who the host names | The laptop — the machine that is asking. | The phone — the machine that is asking. | The laptop — the LAN IP you wrote down. |
| Does the page load | Yes. The server is on this machine. | No. The phone asked itself. | Yes, on the same Wi-Fi. |
| Log first field | 127.0.0.1 | None on the laptop. The request never left the phone. | The phone — not 127.0.0.1. |
If you typed the LAN URL and the page still fails, look at the laptop.
Watch the terminal while you reload the phone.
If no new log line appears, the request never reached the server.
A firewall is a filter that can block inbound connections.
The bind can be 0.0.0.0 and the packet can still stop there.
On Windows / WSL. A Windows browser can reach WSL at
localhost. The phone cannot. Default NAT often blocks LAN. The last page of this unit has the documented path.
What you carry forward
The same file now loads at http://192.168.x.x:8000 on a second device.
The access log shows that client.
You have three addresses for one file. The next page writes the two lines that start and stop this.
Flashcards
Why http://localhost:8000 fails on the phone.
localhost is the machine that is asking. The phone asked itself.
127.0.0.1
Loopback. This machine only. It must not appear outside a host.
0.0.0.0 as a bind address
All interfaces. The server will answer on every address this machine has.
How you confirm python3 -m http.server binds all interfaces.
The banner: Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
What --bind 127.0.0.1 would do.
Listen on loopback only. Other devices could not connect, even with the LAN IP.
Quiz
Show answer
Answer: False
The banner's 0.0.0.0 means the server is willing to answer on all interfaces. It does not change what localhost means on the phone. The phone still asks itself. Type the LAN IP you wrote down, not localhost (objectives 1, 2).
The banner's 0.0.0.0 means the server is willing to answer on all interfaces. It does not change what localhost means on the phone. The phone still asks itself. Type the LAN IP you wrote down, not localhost (objectives 1, 2).
Show answer
Answer:
localhost is the machine that is asking. On the laptop that is the laptop, where the server runs. On the phone that is the phone, so the request never reaches the laptop. Type http:// plus the LAN IP you wrote down plus :8000, on the same Wi-Fi. The access log's first field then shows the phone, not 127.0.0.1.
A full-credit answer shows: A strong answer covers (1) that localhost / 127.0.0.1 names the machine that is asking, so the phone asked itself, and (2) that the phone must open http://192.168.x.x:8000 — the number written down in Unit 3 — on the same Wi-Fi.
localhost means this machine only. The laptop asked itself and hit the server. The phone asked itself and missed it. The fix is the LAN URL on the same Wi-Fi, not another loopback spelling. An answer that tells the phone to type localhost, 127.0.0.1, or 0.0.0.0 has mixed up the bind with the host (objectives 1, 3).
Sample answer
localhost is the machine that is asking. On the laptop that is the laptop, where the server runs. On the phone that is the phone, so the request never reaches the laptop. Type http:// plus the LAN IP you wrote down plus :8000, on the same Wi-Fi. The access log's first field then shows the phone, not 127.0.0.1.
A full-credit answer shows
A strong answer covers (1) that localhost / 127.0.0.1 names the machine that is asking, so the phone asked itself, and (2) that the phone must open http://192.168.x.x:8000 — the number written down in Unit 3 — on the same Wi-Fi.
localhost means this machine only. The laptop asked itself and hit the server. The phone asked itself and missed it. The fix is the LAN URL on the same Wi-Fi, not another loopback spelling. An answer that tells the phone to type localhost, 127.0.0.1, or 0.0.0.0 has mixed up the bind with the host (objectives 1, 3).
Show answer
Answer: The phone — the machine that is asking.
localhost is the machine that is asking, so on the phone it names the phone. The laptop is where the server runs, but that is not what the word means on a different device. It is not a shared name for the LAN, and it is not 0.0.0.0 — that is a bind address, not a host the phone types (objective 1).
localhost is the machine that is asking, so on the phone it names the phone. The laptop is where the server runs, but that is not what the word means on a different device. It is not a shared name for the LAN, and it is not 0.0.0.0 — that is a bind address, not a host the phone types (objective 1).