Sending a Message
Leland.Stanford.edu Arachne.Berkeley.edu
Application Layer
Ron Leslie
Transport Layer
D H D H D H
D H Link Layer
Protocol Stack
Application
HTTP, SMTP, FTP,
TELNET, DNS
End-to-End
TCP, UDP
Network
IP
Link Level
End-to-End
TCP, UDP
Network
IP
Link Level
End-to-End
Network: Internet
TCP, UDP Data format: IP packets
Address: IP
Properties: “Best-effort”
Network
IP
Link Level
End-to-End
Network: Internet
TCP, UDP Data format: IP packets
Address: IP
Properties: “Best-effort”
Network
IP
Network: LAN
Data format: Technology
dependent frames
Link Level Properties: MAC addresses
Ethernet, token ring
TCP
Connection-Oriented
Port on “client” connects to port on “server”
Reliable
3-way handshake
Byte-Stream
To application, looks like stream of bytes flowing
between two hosts
Flow Control
Prevents overrunning receiver / network capacity
Establishing the Connection
Client (Active) (Passive)
Sequence # (x) Client Server
Syn
Server
Syn + Ack
ACK (x+1)
Own sequence # (y) Ack
Client
ACK (y+1)
Sequence # (x+1)
Connection Setup
3-way handshake
Maintaining the “Connection”
IP Data
TCP Data TCP Hdr IP Hdr
0 15 31
Src port Dst port
Sequence #
Src/dst port numbers
Ack Sequence #
and IP addresses
Flags
Window Size uniquely identify socket
HLEN RSVD
SYN
PSH
URG
RST
FIN
ACK
4 6
(TCP Options)
TCP Data
Terminating the Connection
(Active) (Passive)
Client Server
Fin
(Data +) Ack
Fin
Ack
Connection Close/Teardown
2 x 2-way handshake
Another Transport Layer Protocol:
UDP
Protocol Stack
App
Link
User Datagram Protocol (UDP)
Characteristics
Connectionless, Datagram, Unreliable
in 192.168.*.* 192.168.1.3
192.168.1.1 1.1.1.1
Internet
Router between
LAN and Internet
IP address (1.1.1.1)
Translates to host 192.168.1.100
address before
forwarding
Five Minute Break
Sockets
Basic Concepts & Important Issues
Client Socket Code & Server Socket Code
Client-Server Interaction
What is a Socket?
Interface to the TCP Byte-Stream (2-way)
Both sides think they are writing to Files!
Example Code
write(SOCK, “Hello\n”);
print SOCK “Hello\n”;
TCP Byte Stream
(Virtual Circuit)
Protocol Stack
Application Application
SOCKETS
Transport Transport
Network Network
Link Link
What is a Port?
Transport address to which processes can
listen for connection requests
Local to host: 1-65535 ports
Well-known ports
Examples
Below 1024 FTP: 21
Standard services HTTP: 80
Only supervisor privileged TELNET: 23
enough to access
Server and Client
host:port
host:port
SSH SSHD
Client Process Server Process
Client Side
Establishing a Connection
Establish Socket Connection
Send & Receive Data
Close Socket Connection
Server listens
Clients call
Chat Server Design
Server State
Who is connected
Max clients connected
Server Abilities
Accept a New Connection
Close a Connection
Client Abilities
Connect to server
Send message to A (thru server handler)
Send message to all (thru server handler)
Leave server