33 Networking
33 Networking
CS 241
University of Illinois
1
The Internet’s Protocol Stack
TCP UDP
IP
3
Why layering?
4
Encapsulation:
Traveling through the layers
Host-to-Host Host-to-Host
5
Network Packet Encapsulation
Source: http://www.tcpipguide.com/free/t_IPDatagramEncapsulation.htm 6
Understanding IP
The network layer provides “host-to-host” connectivity.
• In IP, done via IP Addresses
! Globally unique 32-bit numbers
! Usually written as four 8-bit integers: 127.0.0.1
! IPv6: 128-bits, written as eight sets of 16-bit hexadecimal
numbers (ex: 2001:0DBB:AC10:FE01:0000:0000:0000:C3D4
== 2001:0DBB:AC10:FE01::C3D4)
7
Understanding TCP
TCP provides:
• Port number to identify a process
• Reliable delivery of packets
• Check data integrity via checksums
• Pipe abstraction (stream)
• Congestion control
• Flow control
8
Understanding UDP
UDP provides:
• Port number for process-to-process communication
• Lower-level access to the network via discrete packets
! Greater speed and flexibility
9
Creating a TCP session
Server:
• Creates a socket to listen for incoming connections.
• Must listen on a specific protocol/port.
server client
TCP/80
10
Creating a TCP session
Client:
• Creates a socket to connect to a remote computer.
server client
TCP/80
11
Creating a TCP session
Client:
• Requests a connection to TCP port 80 on 74.125.225.70.
server client
TCP/80
12
Creating a TCP session
Server:
• Accepts the connection.
server client
TCP/80
13
Creating a TCP session
Server:
• Spawns a new socket to communicate directly with the newly
connected client.
• Allows other clients to connect.
server client
Two way
communications
TCP/80
14
Network Vocabulary
Socket Address
• Complete identification of the socket you are connecting to. Made up
of three pieces:
! Protocol (ex: TCP)
! Network Address (ex: 127.0.0.1)
! Port Number (ex: 80)
Port Number
• Globally shared system resource, 16-bit integer (0 to 65,535)
• A port number can only be used by one process at a time on the
entire system
• Ports below 1024 are “special”
! Associated with particular applicaitons
! Use often requires elevated privileges (e.g. root)
15
Network socket
16
Creating a network socket (client and
server)
socket(): Create an endpoint for communication
17
Setting up a server socket
18
Setting up a client socket
19