ByteByte CityCity
All lessons
OSI Model

Ping Works, Page Won't Load: Ports, TCP and UDP | OSI Layer 4

9:32 Watch on YouTube

A user can ping the web server — every reply comes back — but the web page will not load. The data is reaching the right building; it just can't get in. In this episode Professor Flows explains the Transport layer using Byte City: numbered garage doors are ports, the cube truck is TCP, the bullhorn is UDP, and every conversation has a temporary return door.

You'll learn

Chapters

  1. 0:00Ping works, the page won't load
  2. 0:34One lawn sign, many doors: ports
  3. 1:19The three port ranges
  4. 1:56The return door: ephemeral ports and sockets
  5. 2:44The truck calls ahead: the three-way handshake
  6. 3:40Numbered, signed for, redelivered: how TCP delivers
  7. 5:03The bullhorn: UDP, and why late is worse than lost
  8. 6:23The real names, and the wrapping order
  9. 7:26The real thing: ping, Test-NetConnection, netstat
  10. 8:37Exam corner
  11. 8:48Recap and next time

The written lesson

The problem: ping works, the page won't load

A user can ping the web server. Every reply comes back, every time. But the web page will not load.

Ping working means the mail bag reaches the house, so Layers 1, 2 and 3 are all fine. The data is arriving at the right building. It just can't get in. So the question is whether the door is open on the far end. That is Layer 4 of the OSI model: the Transport layer.

One lawn sign, many doors: ports

Three garage doors labelled Ports 443/80 Storefront, Port 25 Mail dock and Port 22 Staff entrance, under a card showing the port ranges 0-1023 well-known, 1024-49151 registered and 49152-65535 dynamic or private
Numbered doors are ports: 65,536 of them, in three ranges.

Layer 3 gets the bag to the right house. But a house isn't one thing. The same server can run a website, a mail service and a remote login, all at once, all behind one lawn sign.

So every house in Byte City has numbered doors. The storefront is the web, and it answers to two numbers: 443 is the secure entrance, HTTPS, which is nearly every website today, and 80 is the older, unlocked one. Door 25 is the mail dock. Door 22 is the staff entrance, for remote administration. The lawn sign gets you to the building. The door number gets you to the right service inside it.

Those door numbers are ports. There are 65,536 of them, in three ranges:

  • 0 to 1023: the well-known ports, the famous doors everybody agrees on.
  • 1024 to 49151: the registered ports, claimed by particular applications.
  • 49152 to 65535: the dynamic or private ports, left free for temporary use.

The return door: ephemeral ports and sockets

A diagram titled The return door. Your computer at 192.168.1.10 has temporary doors 51514 and 51515, each exchanging pieces with door 443 on the server at 10.0.5.20. Below: 192.168.1.10:51514 <-> 10.0.5.20:443, a pair of sockets
Every conversation has a return door. An address plus a door is a socket.

Here is the half people forget. When your computer knocks on door 443, the server needs to know which door to answer at.

So before it sends anything, your computer opens a temporary door of its own, with a high random number. Say, 51514. Every piece it sends is tagged with both: to door 443, from door 51514. The reply comes straight back to that door.

Open a second browser tab and your computer opens a second temporary door. Same house, same server, two separate conversations, and the replies never get mixed up, because each has its own return door.

The return door is an ephemeral port. An address plus a door number is a socket. One conversation is simply a pair of them: 192.168.1.10:51514 and 10.0.5.20:443.

The truck calls ahead: the three-way handshake

A diagram titled The truck calls ahead: the three-way handshake. Three arrows run between a TCP truck and door 443 on the server: SYN, here's my starting number; SYN-ACK, got it, here's mine; ACK, got yours
SYN, SYN-ACK, ACK. Only after the third message is there a connection.

Layer 4 gives you two ways to travel, and they could not be more different. The first is the cube truck. That is TCP, and the truck never just turns up.

Before a single piece of data moves, the driver calls ahead. "I'd like to deliver to door 443. Are you there?" The house answers: "I'm here. Are you ready?" The driver confirms: "Ready."

Three messages. Their real names are SYN, SYN-ACK and ACK, and together they are the three-way handshake. SYN is short for synchronise: each side tells the other where its numbering starts, so the count of pieces that follows means the same thing at both ends.

Only after the third message is there a connection. If that door is shut, the handshake fails on the very first message, and nothing is ever sent. That is exactly what is happening to our user.

Numbered, signed for, redelivered

A diagram titled Numbered, signed for, redelivered. Pieces 2 and 1 have reached the house out of order, 3 and 4 are on the road and 5 has not left the sender. A banner reads First: pieces are numbered
TCP numbers every piece, so the far end can put them back in order.

Once the connection is open, TCP does three things the road never promised.

  1. It numbers. TCP cuts the data into pieces and numbers every one. The internet doesn't guarantee that pieces arrive in the order they left, so the far end uses the numbers to put them back in order.
  2. It takes a signature. For what arrives, the house sends back an acknowledgement. One signature can cover a whole run of pieces: "I have everything up to here." If a signature doesn't come back in time, TCP assumes that piece was lost and sends it again.
  3. It doesn't flood the house. The receiver keeps telling the sender how much it can take at once, and the sender slows down or speeds up to match. That is flow control: the receiver's limit. Congestion control, which watches the road's own limits, is a different mechanism.

Each piece, with its TCP tag, is a segment.

The bullhorn: UDP

A large bullhorn on a post marked UDP, aimed at the 443/80 storefront door of one house. A card reads Shout it once, and leave: no call ahead, no numbering, no signature, no second attempt
UDP is the bullhorn: shout it once at one door, and leave.

The second choice is the bullhorn. That is UDP. You walk up to the right door, shout the message once, and leave. No call ahead. No numbering. No signature. No second attempt. If it wasn't heard, it's gone.

That sounds like a worse deal, until you think about a phone call. If one tiny slice of a voice goes missing, the worst thing you can do is stop everything and deliver it again, two seconds late. You would rather have a tiny gap and keep talking. For anything live, late is worse than lost.

The bullhorn also suits quick questions. A DNS lookup is one small question and one small answer. Setting up a connection first would take longer than the conversation.

And the bullhorn is still aimed at one door. It is not a broadcast.

TCP: the cube truckUDP: the bullhorn
Before sendingCalls ahead: the three-way handshakeNothing. It shouts once at the door
ReliabilityEvery piece numbered, signed for, and sent again if lostNone. If it wasn't heard, it's gone
Described asConnection-oriented, reliableConnectionless, best effort
Each piece is calledA segmentA datagram
Rides itWeb pages, email, file transfers, remote login, video you can rewindVoice and video calls, live streams and games, DNS lookups (UDP 53, TCP for big answers), DHCP (UDP 67 and 68)

Where Layer 4 sits in the wrapping order

The door numbers go on a tag tied directly to the data: the segment. The segment goes into the mail bag, which adds the lawn-sign numbers. The mail bag goes into the crate, which adds the brass plaques. Then the road carries it as bits. Door, address, plaque: Layer 4, 3, 2.

The real thing: test the door, not the house

A Windows PowerShell window running Test-NetConnection 10.0.5.20 -Port 443. The output warns that the TCP connect failed, with PingSucceeded: True and TcpTestSucceeded: False highlighted
PingSucceeded: True. TcpTestSucceeded: False. The building is there. The door is shut.

ping 10.0.5.20 answers, so the house is reachable. The reply says TTL=62: it started at 64 and crossed two routers.

Now test the door, not the house. On Windows, Test-NetConnection 10.0.5.20 -Port 443 tries the handshake for you. PingSucceeded: True. TcpTestSucceeded: False. The building is there. The door is shut.

So look from the inside. On the server, netstat -an lists every door that is open and listening. 22 and 25 are there. 443 and 80 are both missing: the web service had stopped. Start it, and both storefront doors appear as LISTENING. A moment later there is a new line marked ESTABLISHED: her address, her return door 51514, talking to door 443.

Two causes produce this exact symptom: a service that isn't running, or a firewall blocking the port. A stopped service slams the door: a reset comes straight back. A firewall that drops silently leaves you waiting for a timeout.

For the Network+ exam, the handshake order is SYN, SYN-ACK, ACK: the client asks, the server answers and asks back, the client confirms.

Quick answers

What is the difference between TCP and UDP?

TCP sets up a connection, numbers the data, waits for acknowledgements and resends what is lost. UDP sends each message once, with no connection and no resend, which suits live voice, video and quick lookups.

What is a port in networking?

A number from 0 to 65535 that identifies one service on a host. The IP address gets data to the right machine; the port gets it to the right program.

What is the TCP three-way handshake?

Three messages that open a TCP connection: SYN, SYN-ACK, ACK. Each side tells the other where its numbering starts before any data is sent.

What is an ephemeral port?

A temporary, high-numbered port your computer opens for one conversation so the reply has somewhere to come back to. The exam range is 49152 to 65535.

Why can I ping a server but not open the website?

Ping only proves the machine is reachable. The page also needs port 443 or 80 to be open. Either the web service is not running or a firewall is blocking the port.

Key terms

Port
—
the numbered door that identifies a service on a host.
Ephemeral port
—
the temporary return door a client opens for one conversation.
Socket
—
an IP address plus a port; one conversation is a pair of sockets.
Three-way handshake
—
SYN, SYN-ACK, ACK: how TCP opens a connection.
Acknowledgement (ACK)
—
the receiver's signature for the data that arrived.
Flow control
—
the receiver telling the sender how much it can take at once.
Segment
—
one piece of data with its TCP tag. With UDP, the piece is a datagram.
Next: Why VoIP Calls Drop at 32 Seconds: The Session Layer | OSI Layer 5

Quick quiz

Five questions on this lesson. Pick an answer to see why.

  1. 1. A user can ping a web server but the site won't load. Test-NetConnection to port 443 shows PingSucceeded True, TcpTestSucceeded False. Which layer is at fault?
  2. 2. On a server, netstat -an shows ports 22 and 25 LISTENING but no line for 80 or 443. Which service can clients not reach?
  3. 3. A PC opens two browser tabs to the same server on port 443. How does it keep the two conversations from mixing?
  4. 4. Why does a live voice call normally use UDP rather than TCP?
  5. 5. A client connects from source port 50211 to port 443 on a web server. Which statement is correct?

Keep learning

Previous

Thumbnail for Can Print, But No Websites? The Network Layer Explained | OSI Layer 37:17
OSI Model

Can Print, But No Websites? The Network Layer Explained | OSI Layer 3

The mail bag, the road atlas and the gate at the end of the street.

7:17 Watch

Next

Thumbnail for Why VoIP Calls Drop at 32 Seconds: The Session Layer | OSI Layer 58:17
OSI Model

Why VoIP Calls Drop at 32 Seconds: The Session Layer | OSI Layer 5

The delivery window, and the phone call that hangs up at thirty-two seconds.

8:17 Watch

Related

Thumbnail for The OSI Model Explained: 7 Layers in One City9:50
OSI Model

The OSI Model Explained: 7 Layers in One City

A city, seven floors, and why the model lost as a design and won as a language.

9:50 Watch

Related

Thumbnail for Ping Works, Names Don't: DNS and the Application Layer | OSI Layer 78:07
OSI Model

Ping Works, Names Don't: DNS and the Application Layer | OSI Layer 7

The storefront, the mail room and the Yellow Pages, where every conversation begins.

8:07 Watch

Exam objectives: CompTIA Network+ N10-009: 1.1 (OSI model), 1.4 (ports and protocols: TCP and UDP, connection-oriented vs connectionless), 5.5 (netstat, ping, Test-NetConnection).

Byte City is not affiliated with or endorsed by CompTIA.