Fundamentals 7 min read

How Does Data Travel from Client to Server? A Deep Dive into Network Layers

This article explains how data is accurately transmitted from a client to a server by detailing each OSI layer's encapsulation, DNS resolution, ARP discovery, routing table lookup, switch forwarding, router processing, and server decapsulation, complete with Java code examples and diagrams.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How Does Data Travel from Client to Server? A Deep Dive into Network Layers

01 Client-side Data Encapsulation

Java client code (illustrated) shows how the application layer specifies the server domain or IP, port number, and payload, then passes them to the transport layer.

The transport layer treats the payload as its data and prefixes it with a source port (dynamically assigned by the OS in the 49152‑65535 range) and a destination port (fixed in the Java code).

The network layer adds source and destination IP addresses; if a domain name is used, it is resolved via DNS following the sequence: browser cache → operating‑system cache → hosts file → DNS server.

The data‑link layer adds the source MAC address (the client’s NIC) and the destination MAC address of the next‑hop device, because the client cannot know the server’s MAC directly.

ARP broadcasts a request announcing its IP and MAC; hosts on the same subnet reply and update their ARP tables with IP‑to‑MAC mappings.

If the target IP is absent from the ARP table, the routing table (generated from /etc/sysconfig/network-scripts/ifcfg-eth0) is consulted. The table matches the destination IP with the most specific subnet mask to determine the next‑hop IP (gateway) and then looks up that IP’s MAC via ARP.

02 Switch Forwarding

The switch receives the frame, reads the destination MAC at the data‑link layer, consults its ARP table, and forwards the frame out the appropriate port (e.g., Fa2/1) toward the router.

03 Router Routing

The router parses the packet at the network layer, identifies the destination IP (e.g., 192.168.3.6), and consults its routing table to select the correct outgoing interface (e.g., FastEthernet0/1).

It then replaces the destination MAC with the MAC of the next hop (obtained from the router’s ARP table) and forwards the packet to the next switch.

04 Server-side Data Decapsulation

The server receives the frame, strips each layer in reverse order, and finally delivers the payload to the application program. After processing, the server sends a response packet following a similar path, which may differ because intermediate routing can change.

05 Extensions

Additional tools include DNS lookup to view the IP address associated with a domain and traceroute (e.g., tracert or traceroute) to count the number of routing nodes between the client and server.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaroutingTCP/IPARPOSI modelSwitches
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.