Sie sind auf Seite 1von 24

Lecture 20 (Application Layer) Outline

„ Elements of network applications


z Client-server model
iterative vs. concurrent server
z Transport service
connection-oriented vs. connectionless
z Socket programming

CSC4430 – Data Communication and Computer Networks 1


20.1. Elements of Network Applications

„ Network application application


transport
z distributed processes network
data link
running in network hosts physical

z exchange messages to
implement application
z message format and
actions to be taken are
defined by application-
layer protocols
z uses services provided application
application
transport
transport
by lower layer protocols network
network
data link
data link physical
z Typical network app has physical

two pieces: client and


server

CSC4430 – Data Communication and Computer Networks 2


20.1. Elements of Network Applications

„ Client-server paradigm
„ Client:
application
z a program running on the local transport
network
machine requesting service data link
physical
from a server.
z initiates contact with server by request
using the well-known port of the
requested services
z e.g. Web client requests a Web
page
reply
„ Server:
z a program running infinitely on application
transport
the remote machine providing network
data link
service to the clients. physical

z e.g. Web server sends


requested Web page

CSC4430 – Data Communication and Computer Networks 3


20.1. Elements of Network Applications

controlled by UA UA
application
developer Process Process
socket socket
controlled by Transport Internet Transport
operating system service service
Host or client Host or server

„ A user agent is an interface „ A process is a program that


between the user and the is running within a host.
network application. „ Within the same host, two
z Web:browser processes communicate with
z E-mail: mail reader interprocess communication
z streaming audio/video:
defined by the OS.
media player „ Processes running in
z Telnet: terminal
different hosts communicate
with an application-layer
protocol
CSC4430 – Data Communication and Computer Networks 4
20.1. Elements of Network Applications

controlled by UA UA
application
developer Process Process
socket socket
controlled by Transport Internet Transport
operating system service service
Host or client Host or server

„ socket: Internet API „ How does a process “identify”


z API: application the other process with which
programming interface it wants to communicate?
z defines interface between z IP address of host running
application and transport other process
layer z “port number” - allows
z two processes receiving host to determine
communicate by sending to which local process the
data into socket, reading message should be delivered
data out of socket

CSC4430 – Data Communication and Computer Networks 5


20.1. Elements of Network Applications

„ Why IP address is not


enough?
z IP packet is used for
communication between
two hosts
z each host may have many
processes running
z so need to specify which
process to deliver data to
„ Here comes the port number
z a port number is a 16 bits
number located in the TCP
header for identifying a
particular process within a
host

CSC4430 – Data Communication and Computer Networks 6


20.1. Elements of Network Applications

„ Transport service requirements:


z Data loss
some apps (e.g., audio) can tolerate some loss
other apps (e.g., file transfer, telnet) require 100%
reliable data transfer
z 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
z Timing
some apps (e.g., Internet telephony, interactive
games) require low delay to be “effective”
CSC4430 – Data Communication and Computer Networks 7
20.1. Elements of Network Applications

„ Transport service requirements of common


applications:

Application Data Loss Bandwidth Time Sensitive


File transfer No loss Elastic No
e-mail No loss Elastic No
Web documents Loss-tolerant Elastic No
Financial apps No loss Elastic Yes or no
Real-time audio/video Loss-tolerant Audio: 5Kb-1Mb Yes, 100’s msec
Video: 10Kb-5Mb
Stored audio/video Loss-tolerant Same as above Yes, few secs
Interactive games Loss-tolerant Few Kbps up Yes, 100’s msec

CSC4430 – Data Communication and Computer Networks 8


20.1. Elements of Network Applications

„ Services provided by Internet transport protocol.

z TCP service: z UDP service:


connection-oriented: connection-less
setup required between unreliable data transfer
client, server between sending and
reliable transport receiving process
between sending and does not provide:
receiving process connection setup,
flow control: sender won’t reliability, flow control,
overwhelm receiver congestion control,
congestion control: timing, or bandwidth
throttle sender when guarantee
network overloaded

CSC4430 – Data Communication and Computer Networks 9


20.1. Elements of Network Applications

„ Transport service used by Internet applications:


Application Application layer Underlying transport
protocol protocol
File transfer FTP TCP
e-mail SMTP TCP
Web HTTP TCP
Remote terminal access Telnet TCP
Remote file server NSF TCP or UDP
Streaming audio/video Proprietary TCP or UDP
(e.g. RealNetworks)
Internet telephony Proprietary Typically UDP
(e.g. Vocaltec)

CSC4430 – Data Communication and Computer Networks 10


20.2. Iterative vs. Concurrent Server

„ Server types:
z Iterative server
it can handle only one request at a time
other requests have to wait
z Concurrent server
handles several requests concurrently

Connectionless Connectionless Connection-oriented Connection-oriented


iterative concurrent iterative concurrent

CSC4430 – Data Communication and Computer Networks 11


20.2. Iterative vs. Concurrent Server

„ The servers that use UDP are normally iterative.

CSC4430 – Data Communication and Computer Networks 12


20.2. Iterative vs. Concurrent Server

„ The servers that use TDP are normally concurrent.

CSC4430 – Data Communication and Computer Networks 13


20.2. Iterative vs. Concurrent Server

„ How concurrent servers work?


z Step 1: Server creates a listening socket.
The notation {*:21, *:*} indicates the server’s socket pair
The server is waiting for a connection request on port 21.
206.62.226.35

Server Listening
socket
{*:21, *:*}

z Step 2: Connection request from client to server.


198.69.10.2 206.62.226.35

Client
Connection request to
Server Listening
206.62.226.35, port 21 socket
{198.69.10.2:1500, {*:21, *:*}
206.62.226.35:21}

CSC4430 – Data Communication and Computer Networks 14


20.2. Iterative vs. Concurrent Server

„ How concurrent servers work?


z Step 3: Concurrent server forks new child process to handle
client.
The connected socket uses the same local port (21) as
used for the listening socket.
198.69.10.2 206.62.226.35

Client Listening
Server socket
{198.69.10.2:1500, con
206.62.226.35:21}
n ect {*:21, *:*}
ion
fork
Server Connected
(Child) socket

{206.62.226.35:21,
198.69.10.2:1500}

CSC4430 – Data Communication and Computer Networks 15


20.2. Iterative vs. Concurrent Server

„ How concurrent servers work?


z Step 4: Second client connection with the same server.
The client host uses different ports (1500 and 1501) for
client 1 and 2.
TCP must look at all four elements in the socket pair to
determine which endpoint receives an arriving segment.
If a segment arrives from 198.69.10.2 port 1500 destined
for 206.62.226.35 port 21, it is delivered to the first child.
If a segment arrives from 198.69.10.2 port 1501 destined
for 206.62.226.35 port 21, it is delivered to the second
child.

CSC4430 – Data Communication and Computer Networks 16


20.2. Iterative vs. Concurrent Server

198.69.10.2 206.62.226.35
Listening
Client1 Server socket
{198.69.10.2:1500, con {*:21, *:*}
206.62.226.35:21} ne ctio
n fork
Client2 Server Connected
(Child) socket
{198.69.10.2:1501, con
206.62.226.35:21}
ne ctio
n {206.62.226.35:21,
198.69.10.2:1500}
Server Connected
(Child) socket
{206.62.226.35:21,
198.69.10.2:1501}

CSC4430 – Data Communication and Computer Networks 17


20.3. Socket Programming

„ Socket programming:
z Means building client/server applications that
communicate using sockets.
controlled by UA UA
application
developer Process Process
socket socket
controlled by Transport Internet Transport
operating system service service
Host or client Host or server

z Socket:
defines interface between application and transport layer.
is created by the application and controlled by the OS.
two processes communicate by sending data into socket,
reading data out of socket.
CSC4430 – Data Communication and Computer Networks 18
20.3. Socket Programming

„ Socket API:
z Introduced in BSD4.1 UNIX in 1981.
z Two types of transport service via socket API:
UDP – unreliable datagram (connectionless).
TCP – reliable, byte stream-oriented (connection-
oriented).
z Socket:
Datagram socket = UDP socket.
Stream socket = TCP socket.
z Socket address = IP address + port number.

CSC4430 – Data Communication and Computer Networks 19


20.3.1. Socket Programming using TCP

Server (running on hostid) Client


create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()

TCP create socket,


wait for incoming
connection request connection setup connect to hostid, port=x
connectionSocket = clientSocket =
welcomeSocket.accept() Socket()

send request using


read request from clientSocket
connectionSocket

write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket

CSC4430 – Data Communication and Computer Networks 20


20.3.1. Socket Programming using TCP

„ Iterative server
ServerSocket welcomeSocket = new ServerSocket(6789);

while(true) {
Socket connectionSocket = welcomeSocket.accept(); // new request
… // processes the request
}

CSC4430 – Data Communication and Computer Networks 21


20.3.1. Socket Programming using TCP

„ Concurrent server

ServerSocket welcomeSocket = new ServerSocket(6789);

while(true) {
Socket connectionSocket = welcomeSocket.accept(); // new request
A newServerThread(connectionSocket);
}
class ServerThread extends Thread {
B public ServerThread(Socket s) {
….
start(); // calls run()
}
C public void run() {
… // processes the request
}
}

CSC4430 – Data Communication and Computer Networks 22


20.3.2. Socket Programming using UDP

„ Client/server socket interaction

Server (running on hostid) Client


create socket, create socket,
port=x, for clientSocket =
incoming request: DatagramSocket()
serverSocket =
DatagramSocket()
Create, address (hostid, port=x)
send datagram request
using clientSocket
read request from
serverSocket

write reply to
serverSocket
specifying client read reply from
host address, clientSocket
port umber close
clientSocket

CSC4430 – Data Communication and Computer Networks 23


20.4. Further Readings

„ Elements of network applications


z Client-server model : Chapter 23.
iterative vs. concurrent server
z Transport service : Chapter 24.
connection-oriented vs. connectionless
z Socket programming: Ross Section 2.6-2.7.

CSC4430 – Data Communication and Computer Networks 24

Das könnte Ihnen auch gefallen