Sunteți pe pagina 1din 77

System Programming and Computer Control

Client-Server Model: Socket Interface


Slide 1 Process to process delivery UDP and TCP
Process-to-ProcessDelivery:
UDPandTCP
Prepared by: KL First Prepared on: 9-09-07 Last Modified on:
Quality checked by: xxx
Copyright 2007 Asia Pacific Institute of Information Technology
Level-2
System Programming and Computer Control
CE00352-2-SPCC
System Programming and Computer Control Slide 2 Process to process delivery UDP and TCP
Topic & Structure of the lesson
Process to Process Delivery
User Datagram Protocol (UDP)
Transmission Control Protocol (TCP)
System Programming and Computer Control Slide 3 Process to process delivery UDP and TCP
Learning Outcomes
At the end of this session you should be able
to:-
Understand rationale for the existence of the
transport layer the need for process-to-process
delivery.
System Programming and Computer Control Slide 4 Process to process delivery UDP and TCP
Key Terms you must be able to use
Client
Client-server paradigm
Connection establishment
Connection termination
Connectionless service
Connection-oriented service
Ephemeral port number
Finite state machine
Flow control
Keep-alive timer
Persistence timer

Port number
Process-to-process delivery
Receiver window
Retransmission timer
Round-trip time (RTT)
Segment
Sender window
Sequence number
Server
Silly windows syndrome
If you have mastered this topic, you should be able to use the following terms
correctly in your assignments and exams:-
System Programming and Computer Control Slide 5 Process to process delivery UDP and TCP
Key Terms you must be able to use
Sliding window
Socket address
State transition diagram
TCP timer
Three-way handshake
Time-waited timer


Transmission Control
Protocol (TCP)
User datagram
User Datagram Protocol
(UDP)
Well-known port numbers
If you have mastered this topic, you should be able to use the following terms
correctly in your assignments and exams:-
System Programming and Computer Control Slide 6 Process to process delivery UDP and TCP
Position of transport layer
System Programming and Computer Control Slide 7 Process to process delivery UDP and TCP
Transport Layer
The transport layer is the core of the Internet
model. It is the fourth layer in the model. This
layer receives services from the network layer
and provides services to the application layer.
Function of transport layer (Duties)
Packetizing
Connection control
Addressing
Providing reliability
System Programming and Computer Control Slide 8 Process to process delivery UDP and TCP
Transport layer duties
System Programming and Computer Control Slide 9 Process to process delivery UDP and TCP
Packetizing
The transport layer creates packets out of the
message received from the application layer.
Packetizing divides a long message into smaller
ones and encapsulated into the data field of the
transport-layer packet and headers are added.

System Programming and Computer Control Slide 10 Process to process delivery UDP and TCP
Connection control
There are two categories:
Connection-oriented Delivery
Create virtual connection between sender and
receiver
The packets are numbered consecutively and
communication can take place in both directions.
Connectionless Delivery
Treats each packet independently without
connection between them.
System Programming and Computer Control Slide 11 Process to process delivery UDP and TCP
Addressing
The packet carrying the request must specify to
which server program the request must be
delivered.
The request packet must also specify the client
program that sent the packet.
System Programming and Computer Control Slide 12 Process to process delivery UDP and TCP
Providing reliability
A transport layer can provide reliability for the
application program that uses its service.
Flow Control
Performed end to end
Error Control
The entire message arrives at the receiving transport
layer without error (damage, loss, or duplication). Error
correction is usually achieved through retrasmission.
System Programming and Computer Control Slide 13 Process to process delivery UDP and TCP
Process-to-Process Delivery
Node-to-node delivery is responsible for
delivery of frames between two neighboring
nodes over link.
Host-to-host delivery is responsible for delivery
of datagram between two hosts.
Process-to-process delivery communication
takes place between two processes (application
programs).

System Programming and Computer Control Slide 14 Process to process delivery UDP and TCP
The transport layer is responsible for
process-to-process delivery.
Note:
System Programming and Computer Control Slide 15 Process to process delivery UDP and TCP
Types of data deliveries
System Programming and Computer Control Slide 16 Process to process delivery UDP and TCP
Process-to-Process Delivery
1. Client-Server Paradigm
2. Addressing
3. Multiplexing and Demultiplexing
4. Connectionless/Connection-Oriented
5. Reliable/Unreliable



System Programming and Computer Control Slide 17 Process to process delivery UDP and TCP
Client-server Paradigm
A process on the local host, called a client, needs
services from a process usually on the remote host,
called a server.
Operating system today support both multiuser and
multiprogramming environments. A remote computer
can run several server programs at the same time, just
as local computers can run one or more client
programs at the same time.
Local host
Local process
Remote host
Remote process
System Programming and Computer Control Slide 18 Process to process delivery UDP and TCP
Addressing
A transport-layer address, called a port number,
to choose among multiple processes running on
the destination host.
The destination port number is needed for
delivery; the source port number is needed for
the reply.
Ephemeral port number are 16-bit integers
between 0 and 65,535.
System Programming and Computer Control Slide 19 Process to process delivery UDP and TCP
Port numbers
System Programming and Computer Control Slide 20 Process to process delivery UDP and TCP
Addressing
The Internet has decided to use universal port
numbers for servers; these are called well-
known port numbers.
The IP addresses and port numbers play
different roles in selecting the final destination
of data.
The destination IP address defines the host
among the different hosts in the world. After the
host been selected, the port number defines
one of the processes on this particular host.
System Programming and Computer Control Slide 21 Process to process delivery UDP and TCP
IP addresses versus port numbers
System Programming and Computer Control Slide 22 Process to process delivery UDP and TCP
Address IANA Ranges
The IANA (Internet Assigned Number Authority)
has divided the port numbers into three ranges:
Well-known ports. The port ranging from 0 to 1023
are assigned and controlled by IANA.
Registered ports. The ports ranging 1024 to 49,151
are not assigned or controlled by IANA. They can
only be registered with IANA to prevent duplication.
Dynamic ports. The ports ranging from 49,152 to
65,535 are neither controlled nor registered. They
can be used by any process.
System Programming and Computer Control Slide 23 Process to process delivery UDP and TCP
IANA ranges
System Programming and Computer Control Slide 24 Process to process delivery UDP and TCP
Socket address
The combination of an IP address and a port number is called a socket
address.
A transport-layer protocol needs a pair of socket addresses: the client
socket address and the server socket address.
The UDP and TCP header contains the port numbers.
System Programming and Computer Control Slide 25 Process to process delivery UDP and TCP
Multiplexing and demultiplexing
The addressing mechanism allows multiplexing and
demultiplexing by the transport layer.
Multiplexing: At the sender site, there may be several
processes that need to send packets. The protocol
accepts message from different processes. After
adding the header, the transport layer passes the
packet to the network layer.
Demultiplexing: At the receiver site, the transport layer
delivers each message to the appropriate process
based on the port number.
System Programming and Computer Control Slide 26 Process to process delivery UDP and TCP
Multiplexing and demultiplexing
System Programming and Computer Control Slide 27 Process to process delivery UDP and TCP
Connectionless vs Connection-Oriented
A transport-layer protocol can either be connectionless
or connection-oriented.
Connectionless Service
The packets are sent from one party to another with
no need for connection establishment or connection
release.
The packets are not numbered; they may be delayed,
or arrive out of sequence.
There is no acknowledgment either. Example UDP.
System Programming and Computer Control Slide 28 Process to process delivery UDP and TCP
Connection Oriented Service
A connection is first established between the sender and the
receiver. Data are transferred. At the end, the connection is
released. Example: TCP is a connection-oriented protocol.
Connection Establishment
1. Host A sends a packet to announce its wish for connection and includes
its initialization information about traffic from A to B.
2. Host B send a packet to acknowledge (confirm) the request of A.
3. Host B sends a packet that includes its initialization information about
traffic from B to A.
4. Host A sends a packet to acknowledge (confirm) the request of B.
This connection establishment implies four steps. However,
since steps 2 and 3 can occur at the same time, they can be
combined into one step.
System Programming and Computer Control Slide 29 Process to process delivery UDP and TCP
Connection establishment
System Programming and Computer Control Slide 30 Process to process delivery UDP and TCP
Connection Termination
Connection in one direction is terminated, the other party can
continue sending data in the other direction. Therefore, four
actions needed to close the connections in both directions:
1. Host A sends a packet announcing its wish for connection termination.
2. Host B sends a segment acknowledging (confirming) the request of A.
After this, the connection is closed in one direction, but not in the other.
Host B can continue sending data to A.
3. When host B has finished sending its own data, it sends a segment to
indicate that it wants to close the connection.
4. Host A acknowledges (confirms) the request of B.
The four-step connection termination cannot be reduced to
three steps because the two parties may not wish to terminate
at the same time. In other words, connection termination is
asymmetric.
System Programming and Computer Control Slide 31 Process to process delivery UDP and TCP
Connection termination
System Programming and Computer Control Slide 32 Process to process delivery UDP and TCP
Reliable vs Unreliable
The transport-layer service can be reliable or
unreliable.
If the application-layer program needs reliability, we
use a reliable transport-layer protocol by implementing
flow and error control at the transport layer.
This mean a slower and more complex service.
UDP is connectionless and unreliable
TCP is connection-oriented and reliable.
These two can respond to the demands of the
application-layer programs.
System Programming and Computer Control Slide 33 Process to process delivery UDP and TCP
Error control
System Programming and Computer Control Slide 34 Process to process delivery UDP and TCP
User Datagram Protocol (UDP)
1. Port Numbers
2. User Datagram
3. Applications
UDP does not add anything to the services of IP except for providing process-to-
process communication instead of host-to-host communication. Also, it performs
very limited error checking.
UDP is very simple protocol with a minimum of overhead.
UDP is a convenient protocol for multimedia and multicasting applications.
System Programming and Computer Control Slide 35 Process to process delivery UDP and TCP
UDP is a connectionless, unreliable
protocol that has no flow and error
control. I t uses port numbers to
multiplex data from the application
layer.
Note:
System Programming and Computer Control Slide 36 Process to process delivery UDP and TCP
Well-known ports used by UDP
Port Protocol Description
7 Echo Echoes a received datagram back to the sender
9 Discard Discards any datagram that is received
11 Users Active users
13 Daytime Returns the date and the time
17 Quote Returns a quote of the day
19 Chargen Returns a string of characters
53 Nameserver Domain Name Service
67 Bootps Server port to download bootstrap information
68 Bootpc Client port to download bootstrap information
69 TFTP Trivial File Transfer Protocol
111 RPC Remote Procedure Call
123 NTP Network Time Protocol
161 SNMP Simple Network Management Protocol
162 SNMP Simple Network Management Protocol (trap)
System Programming and Computer Control Slide 37 Process to process delivery UDP and TCP
User Datagram Format
Source port number. This is the port number used by the
process running on the source host.
Destination port number. This is the port number used by the
process running on the destination host.
Length. This is a 16-bit field that defines the total length of the
user datagram, header plus data.
Checksum. This field is used to detect errors over the entire
user datagram (header plus data). This ensures that those
fields have not been changed from the source to the
destination. The calculation of the checksum and its inclusion in
a user datagram are option. If the checksum is not calculated,
the field is filled with 0s.
System Programming and Computer Control Slide 38 Process to process delivery UDP and TCP
User datagram format
UDP Packets, called user datagrams, have a fixed-size header of 8 bytes.
System Programming and Computer Control Slide 39 Process to process delivery UDP and TCP
The calculation of checksum and its
inclusion in the user datagram are
optional.
Note:
System Programming and Computer Control Slide 40 Process to process delivery UDP and TCP
Application of UDP
UDP is suitable for a process that requires simple
request-response communication with little concern for
flow and error control. It is not usually used for a
process that needs to send bulk data, such FTP.
Internal flow and error control mechanisms.
Multicasting capabilities are embedded in the UDP
software but not in the TCP software.
UDP is used for some route updating protocols such
as Routing Information Protocol (RIP)
UDP is used in conjunction with the Real Time
Transport Protocol (RTP) to provide a transport-layer
mechanism for real-time data.
System Programming and Computer Control Slide 41 Process to process delivery UDP and TCP
UDP is a convenient transport-layer
protocol for applications that provide
flow and error control. I t is also used
by multimedia applications.
Note:
System Programming and Computer Control Slide 42 Process to process delivery UDP and TCP
Transmission Control Protocol (TCP)
Port Numbers
Services
Sequence Numbers
Segments
Connection
Transition Diagram
Flow and Error Control
Silly Window Syndrome

TCP is called a stream connection-oriented
and reliable transport protocol.
System Programming and Computer Control Slide 43 Process to process delivery UDP and TCP
Port Numbers
Like UDP, TCP uses port numbers as tranport-
layer addresses.
If an application can use both UDP and TCP,
the same port number is assigned to this
application.

System Programming and Computer Control Slide 44 Process to process delivery UDP and TCP
Well-known ports used by TCP
Port Protocol Description
7 Echo Echoes a received datagram back to the sender
9 Discard Discards any datagram that is received
11 Users Active users
13 Daytime Returns the date and the time
17 Quote Returns a quote of the day
19 Chargen Returns a string of characters
20 FTP, Data File Transfer Protocol (data connection)
21 FTP, Control File Transfer Protocol (control connection)
23 TELNET Terminal Network
25 SMTP Simple Mail Transfer Protocol
53 DNS Domain Name Server
67 BOOTP Bootstrap Protocol
79 Finger Finger
80 HTTP Hypertext Transfer Protocol
111 RPC Remote Procedure Call
System Programming and Computer Control Slide 45 Process to process delivery UDP and TCP
Stream delivery
TCP, is steam-oriented protocol. In UDP, a process
(an application program) sends a chunk of bytes to
UDP for delivery. UDP adds its own header to this
chunk of data, which is now called a user datagram,
and delivers it to IP for transmission. The process may
deliver several chunks of data to the UDP, but UDP
treats each chunk independently without seeing any
connection between them.
TCP, on the other hand, allows the sending process to
deliver data as a stream of bytes and the receiving
process to obtain data as a stream of bytes. TCP
creates an environment in which the two processes
seem to be connected by an imaginary. tube that
carries their data across the Internet.
System Programming and Computer Control Slide 46 Process to process delivery UDP and TCP
Stream delivery
System Programming and Computer Control Slide 47 Process to process delivery UDP and TCP
Sending and receiving buffers
The sending and the receiving processes may
not produce and consume data at the same
speed. TCP needs buffers for storage.
There are two buffers, the sending buffer and
the receiving buffer, for each direction.
One way to implement a buffer is to use a
circular array of 1-byte locations.
System Programming and Computer Control Slide 48 Process to process delivery UDP and TCP
Sending and receiving buffers
At the sending site, the buffer has three types of locations. The white section contains
empty locations that can be filled by the sending process.
The blue area hold bytes that have been sent but not yet acknowledged.
The bytes in blue locations area acknowledged, the location is recycled and available
for use by the sending process.
After both processes have no data left to send and the buffers are empty, the two
TCPs destroy their buffers.
System Programming and Computer Control Slide 49 Process to process delivery UDP and TCP
TCP segments
TCP groups a number of bytes together into a packet
called a segment.
TCP adds a header to each segment and delivers the
segment to the IP layer for transmission.
The segments are encapsulated in an IP datagram
and transmitted.
The segments are not necessarily the same size. In
reality segments carry hundreds, if not thousands, of
bytes.
System Programming and Computer Control Slide 50 Process to process delivery UDP and TCP
TCP segments
There is no field for a segment number value. Instead, there are two field called
the sequence number and the acknowledgment number. These two fields refer
to the byte number, not the segment number.
System Programming and Computer Control Slide 51 Process to process delivery UDP and TCP
Byte Numbers
TCP numbers all data bytes that are transmitted
in a connection. Numbering is independent in
each direction.
When TCP receives bytes of data from the
process and stores them in the sending buffer,
it numbers them.
The numbering does not necessary start from
0; it starts with a randomly generated number
between 0 and 2
32
1.
System Programming and Computer Control Slide 52 Process to process delivery UDP and TCP
The bytes of data being transferred in
each connection are numbered by
TCP. The numbering starts with a
randomly generated number.
Note:
System Programming and Computer Control Slide 53 Process to process delivery UDP and TCP
Example 1
Imagine a TCP connection is transferring a file of 6000 bytes. The
first byte is numbered 10010. What are the sequence numbers for
each segment if data are sent in five segments with the first four
segments carrying 1000 bytes and the last segment carrying 2000
bytes?
Solution
The following shows the sequence number for each segment:
Segment 1 ==> sequence number: 10,010 (range: 10,010 to 11,009)
Segment 2 ==> sequence number: 11,010 (range: 11,010 to 12,009)
Segment 3 ==> sequence number: 12,010 (range: 12,010 to 13,009)
Segment 4 ==> sequence number: 13,010 (range: 13,010 to 14,009)
Segment 5 ==> sequence number: 14,010 (range: 14,010 to 16,009)
System Programming and Computer Control Slide 54 Process to process delivery UDP and TCP
The value of the sequence number
field in a segment defines the number
of the first data byte contained in that
segment.
Note:
System Programming and Computer Control Slide 55 Process to process delivery UDP and TCP
The value of the acknowledgment field
in a segment defines the number of the
next byte a party expects to receive.
The acknowledgment number is
cumulative.
Note:
System Programming and Computer Control Slide 56 Process to process delivery UDP and TCP
TCP segment format
The unit of data transfer between two devices
using TCP is a segment.
The segment consist of a 20- to 60-byte
header, followed by data from the application
program.
The header is 20 bytes if there are no options
and up to 60 bytes if it contains options.

System Programming and Computer Control Slide 57 Process to process delivery UDP and TCP
TCP segment format
Next slide discuss the above header fields
System Programming and Computer Control Slide 58 Process to process delivery UDP and TCP
Header
Source port address: This is a 16-bit field that defines
the port number of the application program in the host
that is sending the segment.
Destination port address: receiving the segment.
Sequence number: defines the number assigned to
the first byte of data contained in this segment (range
2
32
). To ensure connectivity, each byte to be
transmitted is numbered. The sequence number tells
the destination which bytes in this sequence
comprises the first byte in the segment.
System Programming and Computer Control Slide 59 Process to process delivery UDP and TCP
Header
Acknowledgment number: This 32-bit field defines the byte
number that the sender of the segment is expecting to receive
from the other party. If the byte numbered x has been
successful received, x+1 is the acknowledgment number.
Header length: This 4-bit field indicates the number of 4-byte
words in the TCP header. The length of the header can be
between 20 and 60 bytes. Therefore, the value of this field can
be between 5 (5x4 = 20) and 15 (15x4 =60).
Reserved: This field defines 6 different control bits or flags
which can be set at a time. These bits enable flow control,
connection establishment and termination, and the mode of
data transfer in TCP.
System Programming and Computer Control Slide 60 Process to process delivery UDP and TCP
Control field
System Programming and Computer Control Slide 61 Process to process delivery UDP and TCP
Description of flags in the control field
Flag Description
URG The value of the urgent pointer field is valid.
ACK The value of the acknowledgment field is valid.
PSH Push the data.
RST The connection must be reset.
SYN Synchronize sequence numbers during connection.
FIN Terminate the connection.
System Programming and Computer Control Slide 62 Process to process delivery UDP and TCP
Three-step connection establishment
System Programming and Computer Control Slide 63 Process to process delivery UDP and TCP
Four-step connection termination
System Programming and Computer Control Slide 64 Process to process delivery UDP and TCP
States for TCP
State Description
CLOSED There is no connection.
LISTEN The server is waiting for calls from the client.
SYN-SENT A connection request is sent; waiting for acknowledgment.
SYN-RCVD A connection request is received.
ESTABLISHED Connection is established.
FIN-WAIT-1
The application has requested the closing of the
connection.
FIN-WAIT-2 The other side has accepted the closing of the connection.
TIME-WAIT Waiting for retransmitted segments to die.
CLOSE-WAIT The server is waiting for the application to close.
LAST-ACK The server is waiting for the last acknowledgment.
System Programming and Computer Control Slide 65 Process to process delivery UDP and TCP
State transition diagram
System Programming and Computer Control Slide 66 Process to process delivery UDP and TCP
A sliding window is used to make
transmission more efficient as well as
to control the flow of data so that the
destination does not become
overwhelmed with data. TCPs sliding
windows are byte-oriented.
Note:
System Programming and Computer Control Slide 67 Process to process delivery UDP and TCP
Sender buffer
System Programming and Computer Control Slide 68 Process to process delivery UDP and TCP
Receiver window
System Programming and Computer Control Slide 69 Process to process delivery UDP and TCP
Sender buffer and sender window
System Programming and Computer Control Slide 70 Process to process delivery UDP and TCP
Sliding the sender window
System Programming and Computer Control Slide 71 Process to process delivery UDP and TCP
Expanding the sender window
System Programming and Computer Control Slide 72 Process to process delivery UDP and TCP
Shrinking the sender window
System Programming and Computer Control Slide 73 Process to process delivery UDP and TCP
I n TCP, the sender window size is
totally controlled by the receiver
window value (the number of empty
locations in the receiver buffer).
However, the actual window size can
be smaller if there is congestion in the
network.
Note:
System Programming and Computer Control Slide 74 Process to process delivery UDP and TCP
Some points about TCPs sliding windows:
Note:
The source does not have to send a full
windows worth of data.
The size of the window can be increased or
decreased by the destination.
The destination can send an acknowledgment
at any time.
System Programming and Computer Control Slide 75 Process to process delivery UDP and TCP
Lost segment
System Programming and Computer Control Slide 76 Process to process delivery UDP and TCP
Lost acknowledgment
System Programming and Computer Control Slide 77 Process to process delivery UDP and TCP
TCP timers

S-ar putea să vă placă și