0% found this document useful (0 votes)
20 views15 pages

Module 5 First Half

This is the module 5 of cn subject

Uploaded by

owaismohammed588
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views15 pages

Module 5 First Half

This is the module 5 of cn subject

Uploaded by

owaismohammed588
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

BCS502 COMPUTER NETWORKS​ III Year – V Sem (2024-25 ODD)

BCS502 COMPUTER NETWORKS


Module-5: Application Layer
Ch. 25. Introduction to Application Layer: Introduction, Client-Server Programming
Ch. 26. Standard Client-Server Protocols: World Wide Web and HTTP, FTP, Electronic Mail, Domain Name
System (DNS), TELNET, Secure Shell (SSH).
Textbook: Ch. 25.1-25.2, 26.1-26.6
-----------------------------------------------------------------------------------------------------------------------------------------------------
Chapter 25: Introduction to Application Layer [P-854]
Introduction, Client-Server Programming
-----------------------------------------------------------------------------------------------------------------------------------------------------
Introduction to Application Layer
●​ The whole Internet, hardware and software, was designed and developed to provide services at the
application layer. The fifth layer of the TCP/IP protocol suite is where these services are provided for
Internet users. The other four layers are there to make these services possible.
●​ Communication is provided using a logical connection, which means that the two application layers
assume that there is an imaginary direct connection through which they can send and receive
messages. Figure shows the idea behind this logical connection.

Providing Services
●​ The Internet was originally designed for the purpose: to provide service to users around the
world. The layered architecture of the TCP/IP protocol suite, however, makes the Internet more
flexible than other communication networks such as postal or telephone networks.
●​ Each layer in the suite was originally made up of one or more protocols, but new protocols can be
added or some protocols can be removed or replaced by the Internet authorities. However, if a
protocol is added to each layer, it should be designed in such a way that it uses the services
provided by one of the protocols at the lower layer. If a protocol is removed from a layer, care
should be taken to change the protocol at the next higher layer that supposedly uses the services of
the removed protocol.
●​ The application layer is different from other layers in that it is the highest layer in the suite. The
protocols in this layer do not provide services to any other protocol in the suite; they only receive
services from the protocols in the transport layer. This means that protocols can be removed from
this layer easily. New protocols can be also added to this layer as long as the new protocols can use
the services provided by one of the transport-layer protocols.
●​ Since the application layer is the only layer that provides services to the Internet user, the flexibility
of the application layer allows new application protocols to be easily added to the Internet, which
has been occurring during the lifetime of the Internet. When the Internet was created, only a few
application protocols were available to the users; today we cannot give a number for these
protocols because new ones are being added constantly.
Standard Application-Layer Protocols
●​ There are several application-layer protocols that have been standardized and documented by the
Internet authority, and we are using them in our daily interaction with the Internet. Each standard
protocol is a pair of computer programs that interact with the user and the transport layer to
provide a specific service to the user.
●​ In the case of these application protocols, we should know what types of services they provide, how
they work, and the options that we can use with these applications, and so on.
●​ The study of these protocols enables a network manager to easily solve the problems that may
occur when using these protocols. The deep understanding of how these protocols work will also
give us some ideas about how to create new nonstandard protocols.
Nonstandard Application-Layer Protocols
●​ A programmer can create a nonstandard application-layer program if you can write two programs
that provide service to the user by interacting with the transport layer.
●​ It is the creation of a nonstandard (proprietary) protocol, which does not even need the approval of
the Internet authorities if privately used, that has made the Internet so popular worldwide.
●​ A private company can create a new customized application protocol to communicate with all of its
offices around the world using the services provided by the first four layers of the TCP/IP protocol
suite without using any of the standard application programs.
●​ What is needed is to write programs, in one of the computer languages that use the available
services provided by the transport-layer protocols.
Application-Layer Paradigms
●​ To use the Internet we need two application programs to interact with each other
o​ one running on a computer somewhere in the world
o​ the other running on another computer somewhere else in the world.
●​ The two programs need to send messages to each other through the Internet infrastructure.
●​ Two paradigms have been developed during the lifetime of the Internet:
o​ the client-server paradigm
o​ the peer-to-peer paradigm.
Traditional Paradigm: Client-Server
●​ The traditional paradigm is called the client-server paradigm. In this paradigm, the service provider
is an application program, called the server process; it runs continuously, waiting for another
application program, called the client process, to make a connection through the Internet and ask
for service.
●​ There are normally some server processes that can provide a specific type of service, but there are
many clients that request service from any of these server processes. The server process must be
running all the time; the client process is started when the client needs to receive service.
●​ Although​ the
communication in the
client-server paradigm is
between two application
programs, the role of each
program is totally different.
In other words, we cannot
run a client program as a
server program or vice
versa.
●​ Figure shows an example of
a​ client-server
communication in which three clients to receive the services
communicate with one server provided by this
server.

●​ One problem with this paradigm is that the concentration of the communication load is on the
server, which means the server should be a powerful computer. Even a powerful computer may
become overwhelmed if a large number of clients try to connect to the server at the same time.
●​ Another problem is that there should be a service provider willing to accept the cost and create a
powerful server for a specific service, which means the service must always return some type of
income for the server in order to encourage such an arrangement. Several traditional services are
still using this paradigm, including the World Wide Web (WWW) and its vehicle HyperText Transfer
Protocol (HTTP), file transfer protocol (FTP), secure shell (SSH), e-mail, and so on.
New Paradigm: Peer-to-Peer
●​ A new paradigm, called the peer-to-peer paradigm (P2P paradigm) has emerged to respond to the
needs​ of​ some​ new
applications. In this
paradigm, there is no
need for a server process
to be running all the time
and waiting for the client
processes to connect. The
responsibility is shared
between peers. A
computer connected to
the Internet can provide
service at one time and
receive service at another
time. A computer can even provide and receive services at the same time. Figure shows an example
of communication in this paradigm.
●​ One of the areas that really fits in this paradigm is the Internet telephony.
Communication by
phone is indeed a peer-to-peer activity; no party needs to be running forever waiting for the other
party to call. Another area in which the peer-to-peer be used is when some
paradigm can

computers connected to the Internet have something to share with each other
●​ Although the peer-to-peer paradigm has been proved to be easily scalable and cost-effective in
eliminating the need for expensive servers to be running and maintained all the time, there are
also some challenges.
●​ The main challenge has been security; it is more difficult to create secure communication between
distributed services than between those controlled by some dedicated servers.
●​ The other challenge is applicability; it appears that not all applications can use this new paradigm.
For example, not many Internet users are ready to become involved, if one day the Web can be
implemented as a peer-to-peer service. There are some new applications, such as BitTorrent,
Skype, IPTV, and Internet telephony that use this paradigm.
Mixed Paradigm
●​ An application may choose to use a mixture of the two paradigms by combining the advantages of
both.
●​ For example, a light-load client-server communication can be used to find the address of the peer
that can offer a service. When the address of the peer is found, the actual service can be received
from the peer by using the peer-topeer paradigm.
-----------------------------------------------------------------------------------------------------------------------------------------------------
CLIENT-SERVER PROGRAMMING
Topics covered
●​ Application Programming Interface
●​ Using Services of the Transport Layer
●​ Iterative Communication Using UDP
●​ Iterative Communication Using TCP
●​ Concurrent Communication
-----------------------------------------------------------------------------------------------------------------------------
●​ In a client-server paradigm, communication at the application layer is between two running
application programs called processes: a client and a server.
●​ A client is a running program that initializes the communication by sending a request; a server is
another application program that waits for a request from a client.
●​ The server handles the request received from a client, prepares a result, and sends the result back
to the client. This definition of a server implies that a server must be running when a request from a
client arrives, but the client needs to be run only when it is needed.
●​ We need to be careful that the server program is started before we start running the client
program. The lifetime of a server is infinite: it should be started and run forever, waiting for the
clients.
●​ The lifetime of a client is finite: it normally sends a finite number of requests to the corresponding
server, receives the responses, and stops.
Application Programming Interface
(Sockets - Socket Addresses - Finding Socket Addresses - Server Site - Client Site)
How can a client process communicate with a server process?
●​ If we need a process to be able to communicate with another process, we need a new set of
instructions to tell the lowest four layers of the TCP/IP suite to open the connection, send and
receive data from the other end, and close the connection. A set of instructions of this kind is
normally referred to as an application programming interface (API).
●​ An interface in programming is a set of instructions between two entities. In this case, one of the
entities is the process at the application layer and the other is the operating system that
encapsulates the first four layers of the TCP/IP protocol suite.
●​ A computer manufacturer needs to build the first four layers of the suite in the operating system
and include an API. In this way, the processes running at the application layer are able to
communicate with the operating system when messages through the
sending and receiving Internet.
●​ Several APIs
have been
designed for
communicatio
n. Three
among them
are common:
socket
interface,
Transport
Layer Interface
(TLI), and
STREAM.

●​ Socket interface started in the early

1980s at UC Berkeley as part of a UNIX


environment. The socket interface is a set
of​ instructions​ that communication p
between the r
o
v
i
d
e
a
p
p
l
i
c
a
t
i
o
n
layer and the operating system, as shown
in Figure.
●​ The idea of sockets allows us to use the set of all instructions already designed in a programming
language for other sources and sinks. For example, in most computer languages, like C, C++, or Java,
we have several instructions that can
read and write data to other sources and
sinks such as a keyboard (a source), a
monitor (a sink), or a file (source and
sink). We can use the same instructions to
read from or write to sockets.
●​ We are adding only new sources and
sinks​ to​ the​ programming​
language
without changing the way we send data or receive data. Figure shows the idea and compares the
sockets with other sources and sinks.
Sockets
●​ Socket is supposed to behave like a terminal
or a file, it is not a physical entity like them; it
is an abstraction. It is an object that is
created and used by the application program.
●​ As far as the application layer is concerned,
communication between a client process and
a server process is communication between
two sockets, created at two ends, as shown in Figure.
●​ The client thinks that the socket is the entity that receives the request and gives the response; the
server thinks that the socket is the one that has a request and needs the response.
●​ If we create two sockets, one at each end, and define the source and destination addresses
correctly, we can use the available instructions to send and receive data. The rest is the
responsibility of the operating system and the embedded TCP/IP protocol.
Socket Addresses
●​ The interaction between a client and a server is two-way communication. In a two-way
communication, we need a pair of addresses: local (sender) and remote (receiver). The local
address in one direction is the remote address in the other direction and vice versa.
●​ Since communication in the client-server paradigm is between two sockets, we need a pair of
socket addresses for communication: a local socket address and a remote socket address. We
need to define a socket address in terms of identifiers used in the TCP/IP protocol suite.
●​ A socket address should first define the computer on which a client or a server is
running. A

computer in the Internet is Internet version. uniquely defined by its IP address, a 32-bit integer
in the current
●​ Several client or server processes may be running at
the same time on a computer, which means that we
need another identifier to define the specific client or
server involved in the communication. An application
program can be defined by a port number, a 16-bit integer. This means that a socket address
should be a combination of an IP address and a port number as shown in Figure.
●​ Since a socket defines the end-point of the communication, we can say that a socket is identified by
a pair of socket addresses, a local and a remote.
Finding Socket Addresses - Server Site
●​ How can a client or a server find a pair of socket addresses for communication? The situation is
different for each site.
●​ The server needs a local (server) and a remote (client) socket address for communication.
●​ Local Socket Address: The local (server) socket address is provided by the operating system. The
operating system knows the IP address of the computer on which the server process is running.
The port number of a server process, however, needs to be assigned. If the server process is a
standard one defined by the Internet authority, a port number is already assigned to it.
- For example, the assigned port number for a Hypertext Transfer Protocol (HTTP) is the integer 80,
which cannot be used by any other process. If the server process is not standard, the designer of
the server process can choose a port number, in the range defined by the Internet authority, and
assign it to the process. When a server starts running, it knows the local socket address.
●​ Remote Socket Address: The remote socket address for a server is the socket address of the client
that makes the connection. Since the server can serve many clients, it does not know beforehand
the remote socket address for communication. The server can find this socket address when a client
tries to connect to the server. The client socket address, which is contained in the request packet
sent to the server, becomes the remote socket address that is used for responding to the client. In
other words, although the local socket address for a server is fixed and used during its lifetime, the
remote socket address is changed in each interaction with a different client.
Finding Socket Addresses - Client Site
●​ The client also needs a local (client) and a remote (server) socket address for communication.
●​ Local Socket Address: The local (client) socket address is also provided by the operating system. The
operating system knows the IP address of the computer on which the client is running. The port
number, however, is a 16-bit temporary integer that is assigned to a client process each time the
process needs to start the communication. The port number, however, needs to be assigned from a
set of integers defined by the Internet authority and called the ephemeral (temporary) port
numbers. The operating system, however, needs to guarantee that the new port number is not
used by any other running client process. The operating system needs to remember the port
number to be able to redirect the response received from the server process to the client process
that sent the request.
●​ Remote Socket Address: Finding the remote (server) socket address for a client, however, needs
more work. When a client process starts, it should know the socket address of the server it wants to
connect to. We will have two situations in this case.
1.​Sometimes, the user who starts the client process knows both the server port number and IP
address of the computer on which the server is running. This usually occurs in situations when
we have written client and server applications and we want to test them. For example, write
some simple client and server programs and we test them using this approach. In this
BCS502 COMPUTER NETWORKS​ III Year – V Sem (2024-25 ODD)

situation, the programmer can provide these two pieces of information when he runs the client
program.
2.​Although each standard application has a well-known port number, most of the time, we do
not know the IP address. This happens in situations such as when we need to contact a web
page, send an e-mail to a friend, copy a file from a remote site, and so on. In these situations,
the server has a name, an identifier that uniquely defines the server process. Examples of
these identifiers are URLs, such as www.xxx.yyy, or e-mail addresses, such as [email protected].
The client process should now change this identifier (name) to the corresponding server socket
address. The client process normally knows the port number because it should be a well-
known port number, but the IP address can be obtained using another client-server application
called the Domain Name System (DNS).
-----------------------------------------------------------------------------------------------------------------------------
Using Services of the Transport Layer
●​ A pair of processes provide services to the users of the Internet, human or programs.
●​ A pair of processes need to use the services provided by the transport layer for communication
because there is no physical communication at the application layer.
●​ There are three common transport-layer protocols in the TCP/IP suite: UDP, TCP, and SCTP. Most
standard applications have been designed to use the services of one of these protocols.
●​ When we write a new application, we can decide which protocol we want to use. The choice of the
transport layer protocol seriously affects the capability of the application processes.
UDP Protocol
●​ UDP provides connectionless, unreliable, datagram service. Connectionless service means that
there is no logical connection between the two ends exchanging messages. Each message is an
independent entity encapsulated in a datagram. UDP does not see any relation (connection)
between consequent datagrams coming from the same source and going to the same destination.
●​ UDP is not a reliable protocol. Although it may check that the data is not corrupted during the
transmission, it does not ask the sender to resend the corrupted or lost datagram.
●​ For some applications, UDP has an advantage: it is message-oriented. It gives boundaries to the
messages exchanged. An application program may be designed to use UDP if it is sending small
messages and the simplicity and speed is more important for the application than reliability. For
example, some management and multimedia applications fit in this category.
TCP Protocol
●​ TCP provides connection-oriented, reliable, byte-stream service. TCP requires that two ends first
create a logical connection between themselves by exchanging some connection-establishment
packets. This phase, which is sometimes called handshaking, establishes some parameters between
the two ends, including the size of the data packets to be exchanged, the size of buffers to be used
for holding the chunks of data until the whole message arrives, and so on.
●​ After the handshaking process, the two ends can send chunks of data in segments in each direction.
By numbering the bytes exchanged, the continuity of the bytes can be checked.
●​ For example, if some bytes are lost or corrupted, the receiver can request the resending of those
bytes, which makes TCP a reliable protocol. TCP also can provide flow control and congestion
control.
●​ One problem with the TCP protocol is that it is not message-oriented; it does not put boundaries
on the messages exchanged. Most of the standard applications that need to send long messages
and require reliability may benefit from the service of the TCP.
SCTP Protocol
●​ SCTP provides a service which is a combination of the two other protocols. Like TCP, SCTP provides a
connection-oriented, reliable service, but it is not byte-stream oriented.
●​ It is a message-oriented protocol like UDP. In addition, SCTP can provide multi-stream service by
providing multiple network-layer connections.
●​ SCTP is normally suitable for any application that needs reliability and at the same time needs to
remain connected, even if a failure occurs in one network-layer connection.
-----------------------------------------------------------------------------------------------------------------------------
Iterative Communication Using UDP
●​ Communication between a client program and a server program can occur
iteratively or

concurrently. Although several client programs can access the same server program at the same
time, the server program can be designed to respond iteratively or concurrently.
●​ An iterative server can process one client request at a time; it receives a request, processes it, and
sends the response to the requestor before handling another request. When the server is handling
the request from a client, the requests from other clients, and even other requests from the same
client, need to be queued at the server site and wait for the server to be freed.
●​ The received and queued requests are handled in the first-in, first-out fashion. In this section, we
discuss iterative communication using UDP.
Sockets Used for UDP
●​ In UDP communication, the
client and server use only one
socket each. The socket created
at the server site lasts
forever; the socket created at
the client site is closed
(destroyed) when the client
process terminates. Figure
shows the lifetime of the
sockets in the server and client
processes.
●​ Different clients use different sockets, but the server creates only one socket and changes only the
remote socket address each time a new client makes a connection. This is logical, because the
server does know its own socket address, but does not know the socket addresses of the clients
who need its services; it needs to wait for
the client to connect before part of the socket filling this
address.
Flow Diagram

●​ UDP provides a connectionless service, in


which a client sends a request and the
server sends back a response. Figure
shows a simplified flow diagram for
iterative communication.
●​ There are multiple clients, but only one
server. Each client is served in each
iteration of the loop in the server. Note
that there is no connection establishment
or connection termination.
●​ Each client sends a single datagram and
receives a single datagram.
●​ In other words, if a client wants to send two datagrams, it is considered as two clients for the server.
The second datagram needs to wait for its turn. The diagram also shows the status of the socket
after each action.
Server Process
●​ The server makes a passive open, in which it becomes ready for the communication, but it waits
until a client process makes the connection. It creates an empty socket. It then binds the socket to
the server and the well-know port, in which only part of the socket (the server socket address) is
filled (binding can happen at the time of creation depending on the underlying language).
●​ The server then issues a receive request command, which blocks until it receives a request from a
client. The server then fills the rest of the socket (the client socket section) from the information
obtained in the request. The request is the process and the response is sent back to the client.
●​ The server now starts another iteration waiting for another request to arrive (an infinite loop).
Note that in each iteration, the socket becomes only half-filled again; the client socket address is
erased. It is totally filled only when a request arrives.
Client Process
●​ The client process makes an active open.
●​ It starts a connection. It creates an empty socket and then issues the send command, which fully
fills the socket, and sends the request.
●​ The client then issues a receive command, which is blocked until a response arrives from the server.
The response is then handled and the socket is destroyed.
-----------------------------------------------------------------------------------------------------------------------------
Iterative Communication Using TCP
●​ TCP is a connection-oriented protocol.
●​ Before sending or receiving data, a connection needs to be established between the client and the
server.
●​ After the connection is established, the two parties can send and receive chunks of data as long as
they have data to do so.
●​ Although iterative communication using TCP is not very common, because it is simpler.
Sockets Used in TCP
●​ The TCP server uses two different sockets, one for connection establishment (listen socket) and the
other for data transfer (socket). The reason for having two types of sockets is to separate the
connection phase from the
data exchange phase.
●​ A server uses a listen socket
to listen for a new client
trying​ to​ establish
connection.
●​ After the connection is
established, the server
creates a socket to exchange
data with the client and
finally to terminate the
connection. The client uses
only one socket for both
connection establishment and data exchange (see Figure).
Flow Diagram
●​ Figure shows a simplified flow diagram
for iterative communication using TCP.
There are multiple clients, one server. but only

●​ Each client is served in each iteration


of the loop. The flow diagram is almost
similar to the one for UDP, but there
are differences that we explain for
each site.
Server Process
●​In Figure, the TCP server process, like
the UDP server process, creates a
socket and binds it, but these two
commands create the listen socket to
be used only for the connection
establishment phase.
●​The server process then calls the listen
procedure, to allow the operating
system to start accepting the clients,
completing the connection phase, and
putting them in the waiting list to be
served.
●​The server process now starts a loop and serves the clients one by one. In each iteration, the server
process issues the accept procedure that removes one client from the waiting list of the connected
clients for serving.
●​If the list is empty, the accept procedure blocks until there is a client to be served. When the accept
procedure returns, it creates a new socket for data transfer. The server process now uses the client
socket address obtained during the connection establishment to fill the remote socket address field
in the newly created socket. At this time the client and server can exchange data.
Client Process
●​The client flow diagram is almost similar to the UDP version except that the client data-transfer box
needs to be defined for each specific case.
-----------------------------------------------------------------------------------------------------------------------------
Concurrent Communication
●​ A concurrent server can process several client requests at the same time. This can be done using
the available provisions in the underlying programming language.
●​ In C, a server can create several child processes, in which a child can handle a client. In Java,
threading allows several clients to be handled by each thread.
-----------------------------------------------------------------------------------------------------------------------------

You might also like