Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Title: Module 2notes for computer networks
Description: 2 nd year engineering Topics: Principles of network applications Users servers interaction File transfer
Description: 2 nd year engineering Topics: Principles of network applications Users servers interaction File transfer
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
Module 2
Application Layer
MODULE – 2
APPLICATION LAYER
1
...
1 Network Application Architectures
1
...
3 Transport Services available to Applications
1
...
5 Application Layer Protocols
2
...
1 Overview of HTTP
2
...
3 HTTP message Format
3
...
1 Cookies
3
...
3 The Conditional GET
4
...
1 FTP Commands and Replies
5
...
1 SMTP
5
...
3 Mail message format
5
...
DNS; Internet directory service
6
...
2 Overview of How DNS works
6
...
Socket Programming : creating Network Applications
7
...
2 Socket Programming with TCP
1
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Network application development is writing programs that run on different end systems
and communicate with each other over network
...
Ex: In Web application there are two distinct programs that communicate with each
other: Browser program running in the user’s host (desktop, laptop, tablet, smartphone,
and so on) and Web server program running in the Web server host
...
This software could be written, for example, in C, Java, or Python
...
Even if you wanted to write application software for these
network-core devices, you wouldn’t be able to do so as shown in figure 1
...
1 Network Application Architectures
The network architecture is fixed and provides a specific set of services to applications
...
1
...
1 Client-server architecture:
There is an always-on host, called the server, which services requests from many other
hosts, called clients
...
The server has a fixed, well-known address, called an IP address
...
Example: Web, FTP, Telnet, and e-mail
...
For example, a popular social-networking site can quickly become overwhelmed if it
has only one server handling all of its requests
...
g : search engines (e
...
, Google and Bing), Internet
commerce (e
...
, Amazon and e-Bay), Web-based email (e
...
, Gmail and Yahoo Mail),
social networking (e
...
, Facebook and Twitter)
1
...
2 P2P architecture:
There is minimal (or no) dedicated servers in data centers
...
The peers are not owned by the service provider, but are instead desktops and laptops
controlled by users
...
The peers communicate without passing through a dedicated server, the architecture is
called peer-to-peer as shown in figure 3
...
g
...
One of the most compelling features of P2P architectures is their self-scalability
...
P2P architectures are also cost effective, since they normally don’t require significant
server infrastructure and server bandwidth
...
ISP Friendly
...
2
...
Because of their highly distributed and open nature, P2P applications can be a
challenge to secure
...
Incentives
...
Figure 3 : Peer- Peer architecture
1
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Processes on two different end systems communicate with each other by exchanging
messages across the computer network
...
1
...
1 Client and Server Processes
A network application consists of pairs of processes that send messages to each other over
a network
...
For each pair of communicating processes, typically label one of the two processes as
the client and the other process as the server
...
With P2P file sharing, the peer that is downloading the file is labeled as the client, and
the peer that is uploading the file is labeled as the server
...
A process in a P2P file-sharing system can both upload and download files
...
The process that waits to be contacted to begin the session is the server
...
2
...
Ex:
A process is analogous to a house and its socket is analogous to its door
...
This sending process assumes that there is a transportation infrastructure on the other side
of its door that will transport the message to the door of the destination process
...
It is also referred to as the Application Programming Interface (API) between the
application and the network, since the socket is the programming interface with
which network applications are built
...
The only control that the application developer has on the transport-layer side is
The choice of transport protocol
The ability to fix a few transport-layer parameters such as maximum buffer and
maximum segment sizes
...
2
...
In the Internet, the host is identified by its IP address
...
In general a host could be running many network applications
...
Popular applications have been assigned specific port numbers
...
A mail server process
(using the SMTP protocol) is identified by port number 25
...
3 Transport Services Available to Applications
A socket is the interface between the application process and the transport-layer protocol
...
The transport-layer protocol has the responsibility of getting the messages to the socket
of the receiving process
...
Consider the protocol with the services which match your application
Ex: Choose train or aeroplane to travel between cities
Classify the services of a protocol with 4 parameters-
Many networks, including the Internet, provide more than one transport-layer protocol
...
Reliable Data Transfer
For many applications—such as electronic mail, file transfer, remote host access, Web
document transfers, and financial applications—data loss can have devastating
consequences
...
If a protocol provides such a guaranteed data delivery service, it is said to provide
reliable data transfer
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
When a transport protocol provides this service, the sending process can just pass its data
into the socket and know with complete confidence that the data will arrive without
errors at the receiving process
...
This may be acceptable for loss-tolerant applications, most notably multimedia
applications such as conversational audio/video that can tolerate some amount of data
loss
...
Throughput
Throughput refers to how much data can be transferred from one location to another in
a given amount of time
...
Applications that have throughput requirements are said to be bandwidth-sensitive
applications
...
Many current multimedia applications are bandwidth sensitive, although some
multimedia applications may use adaptive coding techniques to encode digitized voice or
video at a rate that matches the currently available throughput
...
Electronic mail, file transfer, and Web transfers are all elastic applications
...
Timing
A transport-layer protocol can also provide timing guarantees
...
An example guarantee might be that every bit that the sender pumps into the socket
arrives at the receiver’s socket no more than 100 msec later
...
d
...
For example, in the sending host, a transport protocol can encrypt all data transmitted by
the sending process, and in the receiving host, the transport-layer protocol can decrypt the
data before delivering the data to the receiving process
...
A transport protocol can also provide other security
services in addition to confidentiality, including data integrity and end-point
authentication
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
1
...
Each of these protocols offers a different set of
services to the invoking applications as shown in figure 5
...
2
...
1 TCP and UDP services
a
...
When an application invokes TCP as its transport protocol, the application receives both
of these services from TCP
...
TCP has the client and server exchange transport layer control information with each
other before the application-level messages begin to flow
...
After the handshaking phase, a TCP connection is said to exist between the sockets of
the two processes
...
Reliable data transfer service
...
When one side of the application passes a stream of bytes into a socket, it can count on
TCP to deliver the same stream of bytes to the receiving socket, with no missing or
duplicate bytes
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
The TCP congestion-control mechanism throttles a sending process (client or server)
when the network is congested between sender and receiver
...
UDP Services
UDP is a no-frills, lightweight transport protocol, providing minimal services
...
UDP provides an unreliable data transfer service—that is, when a process sends a
message into a UDP socket, UDP provides no guarantee that the message will ever reach
the receiving process
...
2
...
2 Services Not Provided by Internet Transport Protocols
These applications have chosen TCP primarily because TCP provides reliable data
transfer, guaranteeing that all data will eventually get to its destination
...
E-mail, remote terminal access, the Web, and file transfer all use TCP
...
Popular Internet applications, their application-layer protocols, and their underlying
transport protocols as shown in figure 6
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Many firewalls are configured to block UDP traffic, Internet telephony applications often
are designed to use TCP as a backup if UDP communication fails
...
3 Application-Layer Protocols
An application-layer protocol defines how an application’s processes, running on
different end systems, pass messages to each other
...
The types of messages exchanged, for example, request messages and response
messages
b
...
The Semantics of the fields, that is, the meaning of the information in the fields
d
...
An application-layer protocol is only one piece of a network application
...
The Web application consists of many components, including a standard for document
formats (that is, HTML), Web browsers (for example, Firefox and Microsoft Internet
Explorer), Web servers (for example, Apache and Microsoft servers), and an applicationlayer protocol
...
Thus, HTTP is only one piece
(albeit, an important piece) of the Web application
...
The Web and HTTP
2
...
HTTP is implemented in two programs: a client program and a server program
...
HTTP defines the structure of these messages and how the client and server exchange the
messages
...
An object is simply a file—
such as an HTML file, a JPEG image, a Java applet, or a video clip—that is addressable
by a single URL
...
For
example, if a Web page contains HTML text and five JPEG images, then the Web page
has six objects: the base HTML file plus the five images
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Each URL has two components: the hostname of the server that houses the object and the
object’s path name
...
someSchool
...
gif
...
1
...
The HTTP client first initiates a TCP connection with the server
...
On the client side the socket interface is the door between the client process and the TCP
connection
...
The client sends HTTP request messages into its socket interface and receives HTTP
response messages from its socket interface
...
Once the client sends a message into its socket interface, the message is out of the client’s
hands and is “in the hands” of TCP
...
HTTP follows client/server model
client: a browser that requests, receives, (using HTTP protocol) and "displays" Web
objects
server: Web server sends (using HTTP protocol) objects in response to requests
HTTP connection types
1
...
Persistent HTTP
2
...
When this
client-server interaction is taking place over TCP, the application developer needs to make an
important decision––should each request/response pair be sent over a separate TCP
connection
...
2
...
In other words, the connection is used exactly for one
request and one response as shown in figure 7
...
Non-persistent connections are the default mode for HTTP/1
...
suppose a user enters URL: www
...
edu/someDepartment/home
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Figure 7 : Example illustrating Non-Persistent http
1
...
someSchool
...
Associated with the TCP connection, there will be a socket at the client and a socket at the
server
...
The HTTP client sends an HTTP request message to the server via its socket
...
index
...
The HTTP server process receives the request message via its socket, retrieves the
object /someDepartment/home
...
4
...
(But TCP doesn’t
actually terminate the connection until it knows for sure that the client has received the
response message intact
...
The HTTP client receives the response message
...
The message indicates that the encapsulated object is an HTML file
...
The first four steps are then repeated for each of the referenced JPEG objects
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
RTT (Round Trip Time) –
It is the time taken for a small packet to travel from client to server and then back to the
client
...
To this end, we define the round-trip time (RTT), which is the time it takes for a small
packet to travel from client to server and then back to the client
...
The browser to initiate a TCP connection between the browser and the Web server; this
involves a “three-way handshake”—the client sends a small TCP segment to the server,
the server acknowledges and responds with a small TCP segment, and, finally, the client
acknowledges back to the server
...
After completing the first
two parts of the handshake, the client sends the HTTP request message combined with the
third part of the three-way handshake (the acknowledgment) into the TCP connection
...
Figure 8: Back-of-the-envelope calculation for the time needed to request and receive an
HTML file
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Non-persistent connections have some shortcomings
...
For each of these connections, TCP buffers must be allocated and TCP variables must be
kept in both the client and server
...
2
...
2 HTTP with Persistent Connections
The server leaves the TCP connection open after sending a response
...
An entire Web page can be sent over a single persistent TCP connection
...
These requests for objects can be made back-to-back, without waiting for replies to
pending requests (pipelining)
...
When the server receives the back-to-back requests, it sends the objects back-to-back
...
Persistent connections are the default mode for HTTP/1
...
2
...
3
...
1 HTTP Request Message
Below we provide a typical HTTP request message:
GET /somedir/page
...
1
Host: www
...
edu
Connection: close
User-agent: Mozilla/5
...
The last line is followed by an additional carriage return and line feed
...
The request line has three fields: the method field, the URL field, and the HTTP
version field
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
The great majority of HTTP request messages use the GET method
...
Methods field :
i
...
ii
...
Instead, HTML forms often use the GET
method and include the inputted data in the requested URL
...
HEAD method: It is similar to the GET method
...
Application developers often use the HEAD method for debugging
...
PUT method: It is often used in conjunction with Web publishing tools
...
The PUT
method is also used by applications that need to upload objects to Web servers
...
DELETE: This method allows a user, or an application, to delete an object on a Web
server
...
someschool
...
Connection: close header line, the browser is telling the server that it doesn’t want to
bother with persistent connections; it wants the server to close the connection after
sending the requested object
...
Here the user agent is Mozilla/5
...
This header line is useful because the server can actually send different versions of the
same object to different types of user agents
...
The Accept-language: header is just one of many content
negotiation headers available in HTTP
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Example :
1
...
4
...
HTTP/1
...
2
...
)
Below figure 9 shows three sections: an initial status line, six header lines, and then the
entity body
...
The status line has three fields: the protocol version field, a status code, and a
corresponding status message
...
1 and that
everything is OK
...
The Date: header line indicates the time and date when the HTTP response was created
and sent by the server
...
The Server: header line indicates that the message was generated by an Apache Web
server; it is analogous to the User-agent: header line in the HTTP request message
...
The Last-Modified: header, which we will soon cover in more detail, is critical for
object caching, both inthe local client and in network cache servers
...
The Content-Type: header line indicates that the object in the entity body is HTML
text
...
301 Moved Permanently: Requested object has been permanently moved; the new
URL is specified in Location: header of the response message
...
404 Not Found: The requested document does not exist on this server
...
Example :
telnet cis
...
edu 80
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
GET /~ross/ HTTP/1
...
poly
...
poly
...
You should see a response message that includes the base HTML file of Professor
Ross’s homepage
...
Finally, replace /~ross/ with /~banana/ and see what kind of response message you
get
...
3
...
1 Cookies
A small text file created by a Web site that is stored in the user's computer either
temporarily for that session only or permanently on the hard disk (persistent cookie)
...
Web servers that can handle thousands of simultaneous TCP connections
...
For these purposes, HTTP uses cookies
...
Cookie technology has four components:
(1) a cookie header line in the HTTP response message;
(2) a cookie header line in the HTTP request message;
(3) a cookie file kept on the user’s end system and managed by the user’s browser;
(4) a back-end database at the Web site
...
com for the first time
...
When the request comes into the Amazon Web server, the server creates a unique
identification number and creates an entry in its back-end database by the
identification number
...
For example, the header line might be Set-cookie: 1678
...
The browser then appends a line to the special cookie file that it manages
...
The cookie file already has an entry for eBay, since Susan has visited that site in the
past
...
Specifically, each of her HTTP requests to the Amazon server includes the header
line: Cookie: 1678
...
Use of cookies
Authorization
Recommendations
shopping carts
user session state (Web e-mail)
3
...
The Web cache has its own disk storage and keeps copies of recently requested objects
in this storage
...
The Web cache has its own disk storage and keeps copies of recently requested
objects in this storage
...
As an example,
suppose a browser
is requesting the object
http://www
...
edu/campus
...
Here is what happens
1
...
2
...
If it does, the
Web cache returns the object within an HTTP response message to the client browser
...
If the Web cache does not have the object, the Web cache opens a TCP connection to the
origin server, that is, to www
...
edu
...
After receiving this
request, the origin server sends the object within an HTTP response to the Web cache
...
When the Web cache receives the object, it stores a copy in its local storage and sends a
copy, within an HTTP response message, to the client browser
...
When it sends requests to and
receives responses from an origin server, it is a client
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
When it receives requests from and sends responses to a browser, it is a server
...
Typically a Web cache is purchased and installed by an ISP
...
Web caching has seen deployment in the Internet for two reasons
...
If there is a high-speed connection between the client and the cache, as there often is,
and if the cache has the requested object, then the cache will be able to deliver the
object rapidly to the client
...
A CDN company installs many geographically distributed caches throughout the
Internet, thereby localizing much of the traffic
...
Why Web caching is needed (Required)? OR Advantages of Caching
To reduce response time for a client request
To reduce traffic on an institution’s access link
To enable "poor" content providers to effectively deliver content
3
...
Fortunately, HTTP has a mechanism that allows a cache to verify that its objects are
up to date
...
An HTTP request message is a so-called conditional GET message if
1
...
the request message includes an If-Modified- Since: header line
...
gif HTTP/1
...
exotiquecuisine
...
1 200 OK
Date: Sat, 8 Oct 2011 15:39:29
Server: Apache/1
...
0 (Unix)
Last-Modified: Wed, 7 Sep 2011 09:23:24
Content-Type: image/gif
(data data data data data
...
Importantly, the cache also stores the last-modified date along with the object
...
Since this object may have been modified at the Web server in the past week, the
cache performs an up-to-date check by issuing a conditional GET
...
gif HTTP/1
...
exotiquecuisine
...
FTP (File Transfer Protocol)
File Transfer Protocol (FTP) is the commonly used protocol for exchanging files over
the Network or Internet as shown in figure 11
...
FTP uses client-server architecture
...
Fig
...
The user first provides the hostname of the remote host, causing the FTP client process
in the local host to establish a TCP connection with the FTP server process in the
remote host
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Once the server has authorized the user, the user copies one or more files stored in the
local file system into the remote file system (or vice versa)
...
1
...
data connection
Fig
...
The data connection is used to actually send a file
...
When a user starts an FTP session with a remote host, the client side of FTP (user) first
initiates a control TCP connection with the server side (remote host) on server port
number 21
...
The client side of FTP also sends, over the control connection, commands to change the
remote directory
...
FTP sends exactly one file over the data connection and then closes the data connection
...
Thus, with FTP, the control connection remains open throughout the duration of the user
session, but a new data connection is created for each file transferred within a session
(that is, the data connections are non-persistent)
...
1 FTP Commands and Replies
The commands, from client to server, and replies, from server to client, are sent across
the control connection in 7-bit ASCII format
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
USER username: Used to send the user identification to the server
...
LIST: Used to ask the server to send back a list of all the files in the current remote
directory
...
RETR filename: Used to retrieve (that is, get) a file from the current directory of the remote
host
...
STOR filename: Used to store (that is, put) a file into the current directory\ of the remote
host
...
Electronic mail on the Internet (Email)
As with ordinary postal mail, e-mail is an asynchronous communication medium in which
people send and read messages when it is convenient for them, without having to
coordinate with other people’s schedules
...
Modern e-mail has many powerful features, including messages with attachments,
hyperlinks, HTML-formatted text, and embedded photos
...
1
...
mail servers
3
...
Microsoft Outlook and Apple Mail are examples of user agents for e-mail
...
When Bob wants to read a message, his user agent retrieves the message from his
mailbox in his mail server
...
Each recipient, such as Bob, has a mailbox located in one of the mail servers
...
When Bob wants to access the messages in his mailbox, the mail server containing his
mailbox authenticates Bob (with usernames and passwords)
...
If Alice’s server cannot deliver mail to Bob’s server, Alice’s server holds the
message in a message queue and attempts to transfer the message later
...
SMTP is the principal application-layer protocol for Internet electronic mail
...
SMTP has two sides: a client side, which executes on the sender’s mail server, and a
server side, which executes on the recipient’s mail server
...
When a mail server sends mail to other mail servers, it acts as an SMTP client
...
5
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
It restricts the body (not just the headers) of all mail messages to simple 7-bit ASCII
...
Suppose Alice wants to send Bob a simple ASCII message
...
Alice invokes her user agent for e-mail, provides Bob’s e-mail address (for
example, bob@someschool
...
2
...
3
...
It opens a TCP connection to an SMTP server, running on
Bob’s mail server
...
After some initial SMTP handshaking, the SMTP client sends Alice’s
message into the TCP connection
...
At Bob’s mail server, the server side of SMTP receives the message
...
6
...
SMTP does not normally use intermediate mail servers for sending mail, even when the
two mail servers are located at opposite ends of the world
...
Note: How SMTP transfers a message from a sending mail server to a receiving mail
server ?
First, the client SMTP (running on the sending mail server host) has TCP establish a
connection to port 25 at the server SMTP (running on the receiving mail server host)
...
Once this connection is established, the server and client perform some application-layer
handshaking, just as humans often introduce themselves before transferring information
from one to another
...
Once the SMTP client and server have introduced themselves to each other, the client
sends the message
...
The client then repeats this process over the same TCP connection if it has other
messages to send to the server; otherwise, it instructs TCP to close the connection
...
2 Comparison of SMTP with HTTP
HTTP is mainly a pull protocol-someone loads information on a web server and users
use HTTP to pull the information from the server
...
SMTP requires each message, including the body of each message, to be in seven-bit
ASCII format
...
HTTP does not have this restriction
...
5
...
POP3 (Post Office Protocol)
POP3 is an extremely simple mail access protocol
...
With the TCP connection established, POP3 progresses through three phases:
authorization, transaction, and update
...
During the second phase, transaction, the user agent retrieves messages; also during this
phase, the user agent can mark messages for deletion, remove deletion marks and obtain
mail statistics
...
POP3 is designed to delete mail on the server as soon as the user has downloaded it
...
POP can be thought of as a "store-and-forward" service
...
IMAP (Internet Message Access Protocol)
With POP3 access, once a receiver has downloaded his messages to the local machine, he
can create mail folders and move the downloaded messages into the folders
...
But this paradigm—namely, folders and messages in the local machine—poses a problem
for the roaming user, who would prefer to maintain a folder hierarchy on a remote server
that can be accessed from any computer
...
An IMAP server will associate each message with a folder; when a message first arrives
at the server, it is associated with the recipient’s INBOX folder
...
The IMAP protocol provides commands to allow users to create folders and move
messages from one folder to another
...
Another important feature of IMAP is that it has commands that permit a user agent to
obtain components of messages
...
This feature is useful when there is a low-bandwidth connection (for example, a slowspeed modem link) between the user agent and its mail server
...
6
...
One identifier
for a host is its hostname
...
For these reasons, hosts are also identified by so-called IP
addresses
...
An IP address looks like 121
...
106
...
6
...
People prefer the more mnemonic hostname identifier, while routers prefer fixed-length,
hierarchically structured IP addresses
...
This is the main task of the Internet’s domain name system
(DNS)
...
The DNS protocol runs over UDP and uses port 53
...
Example:
Consider what happens when a browser (that is, an HTTP client), running on some
user’s host, requests the URL www
...
edu/ index
...
In order for the user’s host to be able to send an HTTP request message to the Web
server www
...
edu, the user’s host must first obtain the IP address of
www
...
edu
...
1
...
2
...
someschool
...
3
...
4
...
5
...
DNS provides a few other important services in addition to translating hostnames to IP
addresses:
Host aliasing
...
For example, a hostname such as relay1
...
enterprise
...
com and www
...
com
...
westcoast
...
com is said to be a canonical hostname
...
Mail server aliasing
...
For example, if Bob has an account with Hotmail, Bob’s e-mail address might
be as simple as bob@hotmail
...
However, the hostname of the Hotmail mail server is
more complicated and much less mnemonic than simply hotmail
...
DNS can be
invoked by a mail application to obtain the canonical hostname for a supplied alias
hostname as well as the IP address of the host
...
DNS is also used to perform load distribution among replicated
servers, such as replicated Web servers
...
com, are replicated over
multiple servers, with each server running on a different end system and each having a
different IP address
...
The DNS database contains this set of IP addresses
...
Because a client typically sends its HTTP request message to the IP address that is
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
listed first in the set, DNS rotation distributes the traffic among the replicated servers
...
6
...
In
this centralized design, clients simply direct all queries to the single DNS server, and the
DNS server responds directly to the querying clients
...
The problems with a centralized design
include:
A single point of failure
...
A single DNS server would have to handle all DNS queries
Distant centralized database
...
If we put the single DNS server in New York City, then all queries from Australia
must travel to the other side of the globe, perhaps over slow and congested links
...
Maintenance
...
Not only would this centralized database be huge, but it would have to be updated
frequently to account for every new host
...
2
...
No single DNS server has all of the mappings for all of the hosts in the Internet
...
There are three classes of DNS servers—root DNS servers, top-level domain (TLD) DNS
servers, and authoritative DNS servers—organized in a hierarchy
To understand how these three classes of servers interact, suppose a DNS client wants to
determine the IP address for the hostname www
...
com
...
The client first contacts one
of the root servers, which returns IP addresses for TLD servers for the top-level domain
com
...
com
...
com, which
returns the IP address for the hostname www
...
com as illustrated in figure 16
...
: Portion of the hierarchy of DNS servers
Root DNS servers
...
Although we have referred to each of the 13 root DNS servers
as if it were a single server, each “server” is actually a network of replicated servers, for
both security and reliability purposes
...
Top-level domain (TLD) servers
...
The company Verisign Global Registry Services maintains the TLD servers
for the com top-level domain, and the company Educause maintains the TLD servers for
the edu top-level domain
...
Every organization with publicly accessible hosts on the
Internet must provide publicly accessible DNS records that map the names of those hosts
to IP addresses
...
An organization can choose to implement its own authoritative DNS server to hold these
records; alternatively, the organization can pay to have these records stored in an
authoritative DNS server of some service provider
...
Suppose the host cis
...
edu desires the IP address of gaia
...
umass
...
Also suppose that Polytechnic’s local DNS server is called dns
...
edu and that
an authoritative DNS server for gaia
...
umass
...
umass
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Figure 17 : Interaction of the various DNS servers
The query message contains the hostname to be translated, namely, gaia
...
umass
...
The local DNS server forwards the query message to a root DNS server
...
The local DNS server then resends the query message to one of these TLD servers
...
edu suffix and responds with the IP address of
the authoritative DNS server for the University of Massachusetts, namely,
dns
...
edu
...
umass
...
cs
...
edu
...
In this case, when the intermediate DNS server, dns
...
edu, receives a query for a
host with a hostname ending with cs
...
edu, it returns to dns
...
edu the IP
address of dns
...
umass
...
umass
...
The local DNS server dns
...
edu then sends the query to the authoritative DNS
server, which returns the desired mapping to the local DNS server, which in turn
returns the mapping to the requesting host
...
2
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
If a hostname/IP address pair is cached in a DNS server and another query arrives to the
DNS server for the same hostname, the DNS server can provide the desired IP address,
even if it is not authoritative for the hostname
...
6
...
Each DNS reply message carries one or more resource records
...
In the example records given below, we ignore the TTL field
...
Thus, a
Type A record provides the standard hostname-to-IP address mapping
...
bar
...
com, 145
...
93
...
• If Type=NS, then Name is a domain (such as foo
...
This record is used to route DNS queries further along in A resource record is a four-tuple
that contains the following fields: (Name, Value, Type, TTL) TTL is the time to live of the
resource record; it determines when a resource should be removed from a cache
...
The meaning of Name and Value
depend on Type:
• If Type=CNAME, then Value is a canonical hostname for the alias hostname Name
...
As an example,
(foo
...
bar
...
com, CNAME) is a CNAME record
...
As an example, (foo
...
bar
...
com, MX) is an MX record
...
Note that by using the MX record, a
company can have the same aliased name for its mail server and for one of its other servers
(such as its Web server)
...
If a DNS server is authoritative for a particular
hostname, then the DNS server will contain a Type A record for the hostname
...
3
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Figure 18 : DNS message format
The first 12 bytes is the header section, which has a number of fields
...
This identifier is copied into the reply message to a
query, allowing the client to match received replies with sent queries
...
A 1-bit query/reply flag indicates
whether the message is a query (0) or a reply (1)
...
A 1-bit recursiondesired flag is set when a client (host or DNS server) desires that the DNS server perform
recursion when it doesn’t have the record
...
The question section contains information about the query that is being made
...
In a reply from a DNS server, the answer section contains the resource records for the
name that was originally queried
...
A reply can return
multiple RRs in the answer, since a hostname can have multiple IP addresses (for
example, for replicated Web servers, as discussed earlier in this section)
...
The additional section contains other helpful records
...
The additional section contains a Type A record providing the IP address for
the canonical hostname of the mail server
...
3
...
There are many registrars competing for customers, and the Internet Corporation for
Assigned Names and Numbers (ICANN) accredits the various registrars
...
com with some registrar, you also
need to provide the registrar with the names and IP addresses of your primary and secondary
authoritative DNS servers
...
networkutopia
...
networkutopia
...
212
...
1, and 212
...
212
...
For each of these two
authoritative DNS servers, the registrar would then make sure that a Type NS and a Type A
record are entered into the TLD com servers
...
com, the registrar would insert the following two
resource records into the DNS system:
(networkutopia
...
networkutopia
...
networkutopia
...
212
...
1, A)
7
...
When these two programs are executed, a client process and a server process are
created, and these processes communicate with each other by reading from, and
writing to, sockets
...
If one developer writes code for the client program and another developer writes code
for the server program, and both developers carefully follow the rules of the RFC, then
the two programs will be able to interoperate
...
In this case
the client and server programs employ an application-layer protocol that has not been
openly published in an RFC or elsewhere
...
But because the code does not implement an open protocol, other independent
developers will not be able to develop code that interoperates with the application
...
We present the simple UDP and TCP applications
in Python
...
1 Socket Programming with UDP
Processes running on different machines communicate with each other by sending messages
into sockets
...
The application resides on one side of the door in the house; the transport-layer
protocol resides on the other side of the door in the outside world
...
At the interaction between two communicating processes that use UDP sockets
...
After the packet passes through the sender’s socket, the Internet will use this
destination address to route the packet through the Internet to the socket in the
receiving process
...
A host may be running many network application processes, each with one or more
sockets, it is also necessary to identify the particular socket in the destination host
...
The sending process attaches to the packet a destination address which consists of the
destination host’s IP address and the destination socket’s port number
...
Attaching the source address to the packet is typically not done by the UDP
application code; instead it is automatically done by the underlying operating system
...
The client reads a line of characters (data) from its keyboard and sends the data to the
server
...
The server receives the data and converts the characters to uppercase
...
The server sends the modified data to the client
...
The client receives the modified data and displays the line on its screen
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
Figure 19 : The client-server application using UDP
The client program is called UDPClient
...
py
...
“Good code” would certainly have a few more auxiliary lines, in particular for
handling error cases
...
py
Here is the code for the client side of the application:
from socket import *
serverName = ‘hostname’
serverPort = 12000
clientSocket = socket(socket
...
SOCK_DGRAM)
message = raw_input(’Input lowercase sentence:’)
clientSocket
...
recvfrom(2048)
print modifiedMessage
clientSocket
...
By including
this line, we will be able to create sockets within our program
...
Here, we provide a string
containing either the IP address of the server (e
...
, “128
...
32
...
g
...
poly
...
If we use the hostname, then a DNS lookup will automatically
be performed to get the IP address
...
clientSocket = socket(socket
...
SOCK_DGRAM)
This line creates the client’s socket, called clientSocket
...
(Do not worry about this now The second parameter indicates that the socket is of type
SOCK_DGRAM, which means it is a UDP socket (rather than a TCP socket)
...
Now that the client process’s door has been
created, we will want to create a message to send through the door
...
When this command is executed, the user at the
client is prompted with the words “Input data:” The user then uses her keyboard to input a
line, which is put into the variable message
...
clientSocket
...
(As mentioned earlier, the source address is also attached to the packet,
although this is done automatically rather than explicitly by the code
...
print modifiedMessage
This line prints out modifiedMessage on the user’s display
...
clientSocket
...
The process then terminates
...
py
Let’s now take a look at the server side of the application:
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket
...
recvfrom(2048)
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
modifiedMessage = message
...
sendto(modifiedMessage, clientAddress)
Note that the beginning of UDPServer is similar to UDPClient
...
The first line of code that is significantly different from UDPClient is:
serverSocket
...
Thus in UDPServer, the code (written by the application
developer) is explicitly assigning a port number to the socket
...
UDPServer then enters a while loop; the while loop will allow UDPServer to receive
and process packets from clients indefinitely
...
message,
clientAddress = serverSocket
...
When a packet arrives at
the server’s socket, the packet’s data is put into the variable message and the packet’s source
address is put into the variable clientAddress
...
Here, UDPServer will make use of this
address information, as it provides a return address, similar to the return address with
ordinary postal mail
...
modifiedMessage = message
...
It takes the line sent by the client and uses the
method upper() to capitalize it
...
sendto(modifiedMessage, clientAddress)
This last line attaches the client’s address (IP address and port number) to the capitalized
message, and sends the resulting packet into the server’s socket
...
) The Internet will then deliver the packet to this client address
...
8
...
When creating the TCP connection, associate with it the client socket address (IP
address and port number) and the server socket address (IP address and port number)
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
This is different from UDP, for which the server must attach a destination address to
the packet before dropping it into the socket
...
This is done in the client program by creating a TCP socket
...
After creating its socket, the client initiates a three-way handshake and establishes a
TCP connection with the server
...
During the three-way handshake, the client process knocks on the welcoming door of
the server process
...
In our example below shown in figure 20, the welcoming door is a TCP socket object that we
call serverSocket; the newly created socket dedicated to the client making the connection is
called connectionSocket
...
TCP thus provides a
reliable service between the client and server processes
...
py
Here is the code for the client side of the application:
from socket import *
serverName = ’servername’
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket
...
send(sentence)
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
modifiedSentence = clientSocket
...
close()
Figure 21: The client-server application using TCP
clientSocket = socket(AF_INET, SOCK_STREAM)
This line creates the client’s socket, called clientSocket
...
The second parameter indicates that the socket is
of type SOCK_STREAM, which means it is a TCP socket
...
connect((serverName,serverPort))
Recall that before the client can send data to the server (or vice versa) using a TCP socket, a
TCP connection must first be established between the client and server
...
The parameter of the connect()
method is the address of the server side of the connection
...
sentence = raw_input(‘Input lowercase sentence:’)
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
As with UDPClient, the above obtains a sentence from the user
...
The next
line of code is also very different from UDPClient:
clientSocket
...
Note that the program does not explicitly create a packet and attach the
destination address to the packet, as was the case with UDP sockets
...
The client
then waits to receive bytes from the server
...
recv(2048)
When characters arrive from the server, they get placed into the string modified
...
Characters continue to accumulate in modifiedSentence until the line ends with a carriage
return character
...
close()
This last line closes the socket and, hence, closes the TCP connection between the client and
the server
...
py
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket
...
listen(1)
print ‘The server is ready to receive’
while 1:
connectionSocket, addr = serverSocket
...
recv(1024)
capitalizedSentence = sentence
...
send(capitalizedSentence)
connectionSocket
...
bind((‘’,serverPort))
But with TCP, serverSocket will be our welcoming socket
...
listen(1)
This line has the server listen for TCP connection requests from the client
...
Dept of CSE, GST, Bengaluru
Module 2
Application Layer
connectionSocket, addr = serverSocket
...
The client and server then complete the handshaking, creating a TCP
connection between the client’s clientSocket and the server’s connectionSocket
...
With TCP, all bytes sent from one side not are not only guaranteed to arrive at
the other side but also guaranteed arrive in order
...
close()
In this program, after sending the modified sentence to the client, we close the connection
socket
...
Dept of CSE, GST, Bengaluru
Title: Module 2notes for computer networks
Description: 2 nd year engineering Topics: Principles of network applications Users servers interaction File transfer
Description: 2 nd year engineering Topics: Principles of network applications Users servers interaction File transfer