CPSC 826 Internetworking
Application-Layer Protocols Overview
Client/Server Computing & Socket Programming
Application-layer protocols define: » The types of messages exchanged » The syntax and semantics of messages » The rules for when and how messages are sent
Michele Weigle
Department of Computer Science Clemson University
[email protected] September 1, 2004
application transport network link physical
local ISP
regional ISP
Public protocols (defined in RFCs) » HTTP, FTP, SMTP, POP, IMAP, DNS
Proprietary protocols » RealAudio, RealVideo » IP telephony » …
http://www.cs.clemson.edu/~mweigle/courses/cpsc826
company network
1
Network Working Group Request for Comments: 2616 Obsoletes: 2068 Category: Standards Track W3C/MIT June 1999 Microsoft
R. Fielding J. Gettys J. Mogul H. Frystyk
UC Irvine Compaq/W3C Compaq
L. Masinter P. Leach
Xerox
T. Berners-Lee
W3C/MIT
2
Application-Layer Protocols Outline
The architecture of distributed systems » Client/Server computing » P2P computing » Hybrid (Client/Server and P2P) systems
Hypertext Transfer Protocol -- HTTP/1.1
Abstract The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. It is a generic, stateless, protocol which can be used for many tasks beyond its use for hypertext, such as name servers and distributed object management systems, through extension of its request methods, error codes and headers [47]. A feature of HTTP is the typing and negotiation of data representation, allowing systems to be built independently of the data being transferred.
The programming model used in constructing distributed systems » Socket programming
application transport network link physical
local ISP
regional ISP
Example client/server systems and their application-level protocols » The World-Wide Web (HTTP) » Reliable file transfer (FTP)
HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as "HTTP/1.1", and is an update to RFC 2068 [33].
» E-mail (SMTP & POP) » Internet Domain Name System (DNS) 3
company network 4
Application-Layer Protocols Outline
Example client/server systems and their application-level protocols » » » »
The World-Wide Web (HTTP) Reliable file transfer (FTP) E-mail (SMTP & POP) Internet Domain Name System (DNS)
Application-Layer Protocols
application transport network link physical
application transport network link physical
Outline
Example P2P systems and their application-level protocols » Gnutella » Napster (hybrid) » KaZaA
local ISP
local ISP
regional ISP
Protocol design issues:
regional ISP
» In-band v. out-of-band control signaling » Push v. pull protocols » Persistent v. non-persistent connections
Client/server service architectures » Contacted server responds versus forwards request
company network
company network 5
6
Application-Layer Protocols
Application-Layer Protocols
Client-Server Architecture
Pure P2P Architecture Server:
local ISP
regional ISP
» always-on host » permanent IP address » server farms for scaling
Clients:
company network
» communicate with server » may be intermittently connected » may have dynamic IP addresses » do not communicate directly with each other
No always-on server Arbitrary end systems directly communicate Peers are intermittently connected and change IP addresses Example: Gnutella
local ISP
regional ISP
Highly scalable But difficult to manage
7
company network
8
Application-Layer Protocols
Application-Layer Protocols
Hybrid of Client-Server and P2P
Transport Services
Napster
Data loss Some apps (e.g., audio) can tolerate some loss Other apps (e.g., file transfer, telnet) require 100% reliable data transfer
» File transfer P2P » File search centralized:
Peers register content at central server Peers query same central server to locate content
Instant messaging » Chatting between two users is P2P » Presence detection/location centralized:
Bandwidth Some apps (e.g., multimedia) require minimum amount of bandwidth to be “effective” Other apps (“elastic apps”) make use of whatever bandwidth they get
Timing Some apps (e.g., Internet telephony, interactive games) require low delay to be “effective”
User registers its IP address with central server when it comes online User contacts central server to find IP addresses of buddies
9
10
Internet Applications
Internet Transport Protocols
Transport Service Requirements
Services Provided
Application
Data loss
Bandwidth
Time Sensitive
file transfer e-mail Web documents real-time audio/video
no loss no loss no loss loss-tolerant
no no no yes, 100’s msec
stored audio/video interactive games instant messaging
loss-tolerant loss-tolerant no loss
elastic elastic elastic audio: 5kbps-1Mbps video:10kbps-5Mbps same as above few kbps up elastic
yes, few secs yes, 100’s msec yes and no
11
TCP service: » connection-oriented: setup required between client, server » reliable transport between sending and receiving process » flow control: sender won’t overwhelm receiver » congestion control: throttle sender when network overloaded » does not provide: timing, minimum bandwidth guarantees
UDP service: » unreliable data transfer between sending and receiving process » does not provide: connection setup, reliability, flow control, congestion control, timing, or minimum bandwidth guarantees
Why bother? Why is there a UDP? 12
Internet Applications
The Application Layer
Application and Transport Protocols
The client-server paradigm
Application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony
Application layer protocol
Underlying transport protocol
SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] proprietary (e.g. RealNetworks) proprietary (e.g., Dialpad)
TCP TCP TCP TCP TCP or UDP
Typical network application has two pieces: client and server Client:
application transport network link physical
local ISP reply
» Initiates contact with server (“speaks first”) » Requests service from server » For Web, client is implemented in browser; for e-mail, in mail reader
typically UDP
regional ISP request
Server: » Provides requested service to client » “Always” running » May also include a “client interface”
company network
Server
13
Client/Server Paradigm
Socket programming
Socket-programming using TCP socket
Sockets are the fundamental building block for client/server systems
Sockets are created and managed by applications » Strong analogies with files
a host-local, application created/released, OS-controlled interface into which an application process can both send and receive messages to/from another (remote or local) application process
application transport network link physical
14
Client/Server Paradigm
Client
A socket is an application created, OS-controlled interface into which an application can both send and receive messages to and from another application » A “door” between application processes and end-to-end transport protocols
controlled by application developer
Two types of transport services are available via the socket API:
controlled by operating system
» UDP sockets: unreliable, datagram-oriented communications » TCP sockets: reliable, stream-oriented communications
process socket TCP with buffers, variables
Host (end system) 15
Internet
process socket TCP with buffers, variables
controlled by application developer controlled by operating system
Host (end system) 16
Socket-programming using TCP
Socket-programming using TCP
TCP socket programming model
Network addressing for sockets
A TCP socket provides a reliable bi-directional communications channel from one process to another
Sockets are addressed using an IP address and port number
» A “pair of pipes” abstraction process
process
Local port numbers (e.g., 6500)
socket Process write read
socket
Internet bytes bytes
read write
socket
End System Host (end system)
socket
TCP with buffers, variables
Process
Host (end system)
TCP with buffers, variables
Internet addresses of hosts (e.g., 130.127.48.4)
Internet domain name of host e.g., access.cs.clemson.edu
End System
DNS
17
18
Socket-programming using TCP
Socket-programming using TCP
Socket programming in Java
Socket creation in the client-server model
Client
Server
Internet
socket
bytes bytes
socket
socket
read write Client
Client creates a local TCP socket specifying the host and port number of server process
» Java resolves host names to IP addresses using DNS
Client contacts server » Server process must be running » Server must have created socket that “welcomes” client’s contact
When the client creates a socket, the client’s TCP establishes connection to server’s TCP When contacted by a client, server creates a new socket for server process to communicate with client » This allows the server to talk with multiple clients
process client socket socket host or server
ay e w ak 3- dsh n ha
write read
ake ay handsh TCP 3-w bytes
process “welcoming”
socket socket
connection
socket socket
bytes
Internet
Server
Client 19
20
Socket programming with TCP Example
Simple client-server example
Client structure
Client stdin
client socket socket
stdout
Server welcoming
socket socket
connection
socket socket
The client reads a line of text from standard input and sends the text to the server via a socket The server receives the line of text from the client and converts the line of characters to all uppercase The server sends the converted line back to the client The client receives the converted text and writes it to standard output
Client reads from standard input (inFromUser stream), writes to server via a socket (outToServer stream) Server reads line from a socket Server converts line to uppercase and writes back to client Client reads from socket, (inFromServer stream) prints modified line to standard output Standard
output
Standard input
outToServer
client socket (3)
(2)
(4)
inFromUser
21
Client Process
(1)
Socket programming with TCP Example
Socket programming with TCP Example
Client/server TCP socket interaction in Java
Java client
TCP wait for incoming connection setup connection request connectionSocket = welcomeSocket.accept()
Client (running on shadow1.cs...) create socket, connect to torpedo1.cs.clemson.edu, port=6789
clientSocket = new Socket(...)
read request from connectionSocket
write request using clientSocket
write reply to connectionSocket
read reply from clientSocket
close connectionSocket
close clientSocket
22
import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence;
Server (running on torpedo1.cs.clemson.edu) create socket for incoming request (port=6789) welcomeSocket = new ServerSocket(...)
inFromServer
Socket-programming using TCP
// Create (buffered) input stream using standard input BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in)); System.out.println("Client ready for input");
// Create client socket with connection to server at port 6789
program flow
Socket clientSocket = new Socket("torpedo1.cs.clemson.edu", 6789);
data flow 23
24
Socket programming with TCP Example
Socket programming with TCP Example
Java client II
Java server
// Create output stream attached to socket DataOutputStream outToServer = new DataOutputStream( clientSocket.getOutputStream());
import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence;
// Create (buffered) input stream attached to socket BufferedReader inFromServer = new BufferedReader( new InputStreamReader( clientSocket.getInputStream())); // Write line to server outToServer.writeBytes(sentence + '\n');
// Create “welcoming” socket using port 6789 ServerSocket welcomeSocket = new ServerSocket(6789);
// Read line from server modifiedSentence = inFromServer.readLine();
System.out.println("Server Ready for Connection");
// While loop to handle arbitrary sequence of clients making requests while(true) {
System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close();
// Waits for some client to connect and creates new socket for connection Socket connectionSocket = welcomeSocket.accept();
} // end main } // end class
System.out.println("Client Made Connection"); 25
26
Socket programming with TCP Example
Socket programming with TCP Example
Java server II
Client/server TCP socket interaction in Java
// Create (buffered) input stream attached to connection socket BufferedReader inFromClient = new BufferedReader( new InputStreamReader( connectionSocket.getInputStream())); // Create output stream attached to connection socket DataOutputStream outToClient = new DataOutputStream( connectionSocket.getOutputStream()); // Read input line from socket clientSentence = inFromClient.readLine(); System.out.println("Client sent: " + clientSentence); capitalizedSentence = clientSentence.toUpperCase() + '\n';
// Write output line to socket outToClient.writeBytes(capitalizedSentence); connectionSocket.close(); } // end while; loop back to accept a new client connection } // end main } // end class
Server (running on torpedo1.cs.clemson.edu) create socket for incoming request (port=6789) welcomeSocket = new ServerSocket(...)
TCP wait for incoming connection setup connection request connectionSocket = welcomeSocket.accept()
create socket, connect to torpedo1.cs.clemson.edu, port=6789
clientSocket = new Socket(...)
read request from connectionSocket
write request using clientSocket
write reply to connectionSocket
read reply from clientSocket
close connectionSocket 27
Client (running on shadow1.cs...)
close clientSocket
program flow
data flow 28
Socket-programming using UDP
Socket programming with UDP Example
UDP socket programming model
Client/server UDP socket interaction in Java
A UDP socket provides an unreliable bi-directional communication channel from one process to another
Server (running on torpedo1.cs.clemson.edu)
» A “datagram” abstraction
create socket for incoming request (port=9876) serverSocket = new DatagramSocket()
read request from serverSocket
Process write read
socket
Host (end system)
Client create socket, clientSocket = new DatagramSocket()
create address (torpedo1.cs.clemson.edu, port = 9876) and send datagram using clientSocket
Process
Internet bytes bytes
socket
read write
write reply to serverSocket specifying client IP address and port number
Host (end system) 29
read reply from clientSocket program flow
close clientSocket
data flow 30