Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
University of Prishtina
Faculty of Computer and Electrical Engineering
Telecommunication Department
Mentor:
Prof. Dr. Blerim Rexha
Students:
Rreze Halili [rrezehalili@hotmail.com]
Isuf Tredhaku [faradi33@hotmail.com]
Orges Tafilaj [orgestafilaj@hotmail.com]
Abstract
This seminar work deals with the role of Sockets and TCP (Transmission Control Protocol) in TCP/IP
protocol suit.
By the fact that today, we use the TCP/IP protocols and Internet, not only for entertainment and information,
but for our business by performing transactions, buying and selling products, and delivering services to
customers. And lot more services that Internet providers offer for their costumers, services those that are
available to users by applications. And by the fact that we are continually extending the need for different
applications, TCP/IP continually is extending the infrastructural support and reliability.
But how this reliability is achieved? One of reasons here is network configurations and huge role plays
TCP/IP protocol suit.
And if we talk about reliability implemented in TCP/IP, the first thing we have in mind is TCP protocol.
As we said this will be the subject of our work here.
In the first chapter we have given a useful explanation for TCP/IP in general, and the role of protocols.
Then the second chapter deals with the role of Socket in transport layer of TCP/IP.
Part of transport layer, TCP presents one of the most successful protocols that provides secure transmission,
basic data transfer, reliability, flow control, multiplexing, byte stream and full duplex data transfer. This is
the reason why we have continued with TCP explanation and its performance. This is achieved by separating
its characteristics in number of parts in third chapter.
In every part we have tried to give a simple, logical, and useful explanation. This is the reason that this text
despite being a seminar, with which our group will be estimated, several features here are designed to make
it particularly easy for students to understand Sockets and TCP, from our point of view.
We would be honored if we have achieved this even in a small level.
Faqja2 / 29
Contents
1
Introduction................................................................................................................................ 4
Socket ....................................................................................................................................... 6
Conclusion ..................................................................................................................................... 26
Bibliography .................................................................................................................................. 27
Appendix 1........28
Appendix 229
Faqja3 / 29
1 Introduction
In everyday life we face up with a lot of different applications, which we use for different purposes.
Every time we ask for the best from them, great performance in every aspect. In this way we perform
with different, secure, fast, reliable, and attractive tasks.
To sum up, these applications are changing the way we learn, live, enjoy, communicate, interact etc.
The modern life activities are getting completely centered around or driven by the Internet
applications.
This is the reason why so many people are taking advantage of opportunities presented by Internet.
This created a huge demand for software designers and engineers with skills in creating new Internetenabled applications or porting existing/legacy applications to the Internet platform. The key elements
for developing Internet-enabled applications are a good understanding of the issues involved in
implementing distributed applications and sound knowledge of the fundamental network programming
models. [KC]
In this way, we can separate people in two groups. The first group are those who are not interested in
the way that those applications are available, just search for the best from them, and do not hesitate to
pay for. And the other part, who in fact understand quite well the logic of this business (if we can call
in this way) and are interested to attract the first part with different services, always trying to offer
secure services, and attractive, and they do not hesitate to be paid for this too.
But how is it possible? We are working in a project, while we surf in a web, send a letter to our friend
(maybe to tell that we can not go out tonight, because we have to finish the project), download a lot of
materials for our task and a lot of other things.
In fact there are thousand of processes that are performed in our computer, and a lot of others in
network, that make possible this. And all this stuff is regulated by the number of rules that we call
protocols.
In our case those rules are defined by OSI model, to be more specific TCP/IP (Transport Control
Protocol/Internet Protocol) protocol suite.
The TCP/IP model includes a number of protocols to insure proper communication between
corresponding layers of networked machines Fig1.1.
Faqja4 / 29
As we can see there are seven layers, and for this, questions often are about the use of layered
protocols. Why do we need those layers? And the best way to answer, is taking a simple example.
Two persons want to communicate with each other, and to achieve this they need to speak in the same
transmission medium, and use the same language.
In this way the communication can be seen as a structure with several layers. In the brain layer we
think about what we are going to talk, we prepare the concept for the language layer, which uses the
below layer (the mouth) to produce the sound.
Sound waves use transmission medium to arrive to the destination, where the ear receives
the sound waves, the language is interpreted, and brain receives the information sent by the other
person.
Fig.1.2 Communication
In the same logic work the TCP/IP layers. As we can see from the Fig.1.1 the top layer of TCP/IP is
the Application layer.
The application layer is provided by the program that uses TCP/IP for communication. An application
in a user process cooperating with another process usually on a different host (there is also a benefit to
application communication within a single host). [IBM 2001]
This includes all processes that use Transport layer protocols to deliver data to the Internet layer.
Placed between the Application and Network layer, Transport layer has the task to perform the logical
communication between application processes of different or same host. This host can be directly
connected to it, or may be very far away, and needs to pass routers and a lot of links for the
destination. But how does the Transport layer of the TCP/IP model prepare user data for transmission
to the network? What are some of the issues surrounding Transport layer configuration, management,
and troubleshooting?
Here we can see the importance that Transport layer has. And in this task we face up with the notion
socket, which we are going to explain below.
Faqja5 / 29
2 Socket
Applications involve networking services provided by the transport layer, which is part of the Internet
software stack, often called TCP/IP stack, shown in Fig. 1.3. The transport layer can be one of the two
types of protocols, TCP (Transport Control Protocol) and UDP (User Datagram Protocol).
So we mentioned applications data, and we mentioned transport of these data, but how do we know
which application protocol should data proceed when it comes from the network layer, how those data
will go to the user interface, and how the user will be able to see this.
And why not to ask for the opposite too?
What happens when the user has to send something to network, how the data will find their route or
path to continue?
The fact is that every computer has its own IP address; however, computers often need to
communicate and provide more than one type of service, or to talk to multiple hosts/computers at a
time. For example, there may be multiple FTP sessions, web connections, and chat programs all
running at the same time. To distinguish these services, a concept of ports is used.
Port is a logical access point, represented by a 16-bit integer number. This means that each service
offered by a computer is uniquely identified by a port number.
This is the reason why each packet contains the IP address and the port number on the host in which
the packet was destined.
Just think about this, IP addresses is the house address when a letter is sent via post office, and port
number in the name of a specific person that has to read the letter (it is his letter).
We have come to the fact that packets have IP addresses and port numbers that are useful for the
destination place. This combination of both those, IP address and port number creates a so called
socket address.
Faqja6 / 29
Fig.2.2 Establishment of path for two-way communication between a client and server
By the last sentence we can add too that socket is used like an Application Programming Interface
API.
Interface to what? In our case, it is an interface to use the network, provided by operating system. We
can see this in Fig.2.3.
We can imagine socket like software methodology, a single connection between exactly two pieces of
software that we use to connect different processes (programs) on the same computer or on different
computers.
This looks like plugging in process into another processs socket, with the tendency to make
possible talking by writing and reading the socket. Fig.2.4.
Within the operating system and the application that created a socket, the socket is referred to by a
unique integer number called socket identifier or socket number. The operating system forwards the
payload of incoming IP packets to the corresponding application by extracting the socket address
information from the IP and transport protocol headers and stripping the headers from the application
data.
Faqja7 / 29
Faqja8 / 29
So both, the sending and receiving applications must interact with their operating systems (OS). This
interaction is useful because the OS should set up whatever is necessary for communication to take
place.
Using TCP means creating a virtual connection between two TCP-s to send data. But be careful not to
confuse this with circuits switch or virtual circuit transport method, because TCP is just part of hosts,
end systems, and its performance dose not influence the elements between them. TCP protocol is
totally part of end system, and intermediate elements communicate with different protocols.
Faqja9 / 29
So here we start, one host A that we call client want to start a connection with the other host B that we
call server. (We are going to use host A and host B quite often so get used with it)
Host A begins the connection by sending host B a segment (special name for type of data being in TCP
layer, that we will explain later) with the "Synchronize sequence numbers" (SYN) bit set.
This segment tells host B that A wishes to set up a connection, and it tells B what sequence number
host A will use as a starting number for its segments. (Sequence numbers are used to keep data in the
proper order.) Host B responds to A with a segment that has the "Acknowledgment" (ACK) and SYN
bits set. B's segment acknowledges the receipt of A's segment, and informs A which Sequence Number
host B will start with. Finally, host A sends a segment that acknowledges receipt of B's segment, and
from the last transfer, third stage can transfers the first actual data. [OReilly]. Fig.3.2.
Faqja10 / 29
In fact after segmentation this would continue to the network layer where would be encapsulated in IP
datagram, and then achieve the destination where would pass through the opposite action explained
above.
With stream data transfer, TCP delivers an unstructured stream of bytes identified by sequence
numbers. This service benefits applications because they do not have to chop data into blocks before
handing it off to TCP. Instead, TCP groups bytes into segments and passes them to IP for
delivery.[CIS 2011]
So data coming from the application is referred as a flowing stream. Data can flow fast or slow. To
insure efficient flow of data to and from the application, TCP provides both input and output buffers.
TCP has to think where to put bytes that come from above, and want to take the way to network, it just
can not answer everyone in immediate way.
In the Fig.3.4 we have taken a simple example how this all works. There are two buffers, the sending
buffer and the receiving buffer, one for each direction. Normally the buffers are hundreds or thousands
of bytes, but we have taken a symbolic small number just to explain how it works. We also show the
buffers are in the same size, which is not always the case. In the sending buffer we have the colored
part of the sectors, when we put bits that have been sent but we have not accept jet the confirmation
for correct arrive in destination process.
And the other part of the buffer, when we have bits, that should be put in the segments and sent to
network.
The operation of the buffer at the receiver site is simpler. We have the part that is white and waits for
bytes from source, and the colored sectors that contain received bytes that can be read by the receiving
process. When a byte is read by the receiving process, the sector is recycled and added to the pool of
empty sector.
Faqja11 / 29
does it contains? This is the subject of this part where we are going to talk more about structure of the
TCP segment.
Faqja12 / 29
Header length. This 4-bit field is the part that tell the number of 4-byte words in the TCP header. As
we said before this value can be between 20 and 60 bytes. It indicates where the TCP header ends and
the data begins.
Unused field. Is this part that makes possible to change the value of TCP header, and we let this like a
reserved. We can use in the future, but for now they must be zero.
Control or flag field. This field defines 6 different control bits or flags as shown in fig 1.x. One or
more of these bits can be set at a time. A brief description of each bit is shown in Table 3.1.
Table 3.1
Flag
Description
URG
ACK
PSH
RST
SYN
FIN
Even from the table we can see that the URG bit tells that the sending part of application has put data
that are considered urgent.
ACK bit is used to tell that the data received from the acknowledgment is valid.
PHD bit we use when we need to tell the destination that data should pass immediately in the
application layer.
RST we use to reset the connection. One function for this is to not accept a connection request.
SYN we use to synchronize sequence numbers, and FIN to terminate the connection, no more data for
receiver. [BFSF 2007]
Receive window. The field that is 16 bit field long means that the maximum size of the window is
65,535 bytes, but this can be decided by the receiver. We use this field for flow control that we will
explain later.
Internet checksum. This field is used to detect errors over the entire user.
Urgent data pointer. This l6-bit field, we use when the urgent flag is set, and defines the number that
must be added to the sequence number to obtain the number of the last urgent byte in the data section
of the segment.
Options filed we use when we negotiate the number of TCP header.
Faqja13 / 29
Faqja14 / 29
After connection is established, bidirectional data transfer can take place. The client and server can
both send data and acknowledgments.
Despite the fact that sequence numbers are put in random manner in TCP header, they have important
role, by the fact that they have the control of putting data in the proper order and make possible to
evident if some of segment are missing. Furthermore sequence numbers speak about bytes in TCP and
not packet, which fact enhance even more the security of data transfer.
Same are acknowledgment numbers.
TCP uses acknowledgments to confirm the receipt of data segments. So Acknowledgment Segment
(ACK) performs two functions: positive acknowledgment and flow control. By its function we know
how much data has been received, and how much more the receiver can accept. [OReilly 1999]. And
ACK number speaks, about the bytes and not for packet, segment or datagram.
For example suppose that we have done with the handshaking and we are transferring data
information. And the receiver buffer or the number of bytes that can have is 6000 bytes.
We will explain later the window concept, but for now is enough to know the main role of it.
This tells the sender that can continue sending segments, as long as the total number of bytes that it
sends, is smaller than the buffer of bytes the receiver can accept.
It will put as a sequence number 0 and will transfer 2000 bytes, which means the SEQ=0 and
ACK=2001 (ACK No. = sequence number + bytes read in the segment + 1).
And as the receiver can have until 6000 bytes, will take them and send a segment back, which is form
SEQ=2001, ACK=3001.
The sender will turn back the answer by putting in the SEQ=3001 ACK=4001. So in this way each
byte will be transferred for sure. See Fig.3.8
Faqja15 / 29
Faqja16 / 29
So why to resend another demand for ACK=100? That is the reason why host A stays without going
anything.Fig.3.11.
Faqja17 / 29
RTT, and we mention before the reasons that this time is not a constant, in fact is dynamic, and in this
way we have to take it.
But here is the master here, we take every RTT and using this delta, TCP builds a sample round-trip
delay time. TCP uses this time to build an average time for a packet to be sent and an acknowledgment
to be received. When it calculates a new value from another sample, it will slowly change its timer
delay for the waiting of the ACK packet.
This sample with change from packet to packet, so we have to take an average one to use in general.
Here we come with the notion EstimatedRTT, which is kind of average value for samples that we take
for RTT.
And the expression for this is:
EstimatedRTT = (1-x) EstimatedRTT + x SampleRTT(1)
We have written in the programming language. But we have done this, use just to explain that
EstimatedRTT takes the value of previusEstimatedRTT and adds to this newest value taken lie
SampleRTT.
The value of x is recommend to be taken x=0.125.
So here is the point after we have EstimatedRTT, we know the value after we will resend packet, so
this value is timeout (that I promised that we are going to explain), and if packet do not bring ACK
that we look for, we restart the timer again, which will start running from the EstimatedRTT value
until the end, where it will be zero.
But we hope now the ACK is in correct place, in contrary we have to restart again. And if we repeat
again and again these demands, for ACK that we are looking for. Where is the role of TCP? We are
going to cause congestion in network, we are going to lose the sense of fast transmissions, and cause
confusion here.
But if we want our packet, we do not have another choice. (Only if somebody has found, and we still
do not know).
3.4.2 Doubling the time interval
When we have resent a demand for ACK that we do not have, and the timeout is finished, we said
before that we have to resend again. This in previous explanations would last forever if we have such
problems, but we have TCP implementations that overcome this problem too.
TCP in such case would resend again, but would put another timeout interval. Of course you think this
is different because of formula (1), (I thought like this), but is not, TCP sets the reset timeout interval
twice that the previous one.
If the first timeout interval was set 1 ms, and now the packet was not acknowledgment this will be
another value and will be 2 ms.
And we have that famous question. What happen if this time for mentioned reasons grows
exponentially, will we get the ACK ever?
But again, this is better implemented like this, because packet do not arrive in the desalination for no
reason, they have to travel from routers to routers and from path to path, and is understandable that
they can meet congestion during their way, so they can be late, or even dropped. And if we continue to
send more requests for ACK, this part really gets worse.
That is the reason why each TCP sender resends the demand for ACK later and later.
But the last case that we have to mention here is the fact that, when TCP sender sends packet and the
receiver only resend the first ACK, the sender understands that is missing the second packet, and
performs with the fast retransmission of second packet before the timeout expires. Fig.3.12.
To sum up a retransmission occurs if the retransmission timeout expires or three duplicate ACK
segments have arrived.
Faqja18 / 29
Faqja19 / 29
Faqja20 / 29
Just to explain with a simple example in the fig.3.14. We have taken a graphical view that tells more
about window size.
Where:
A: Bytes that are transmitted and have been acknowledged.
B: Bytes that are sent but not yet acknowledged.
C: Bytes that can be sent without waiting for any acknowledgment.
D: Bytes that cannot be sent yet.
Faqja21 / 29
through the link, and the grow ness becomes in that point that cause that the data bytes in the router
can be processed less than the data that can achieve the buffer, then here it starts the problem.
Depend on the size of buffer, after a while the data will start to get lost. In this way the sender have to
retransmit again those data packet.
In addition, how many data packet get lost in buffer, will cause the degrees of the communication
system.
Despite those all problems, which we have talked before, we have more. Ridicules but this is the truth.
This thank to the fact that data packet pass through a lot routers and different paths, but still some of
them pass through more routers than others.
If we have the time that we face with a lot traffic (so the packet data from host to host is quite large),
the data packet that pass through less routers have more possibility to be saved in buffer, in contrast
others that have passed through more routers have less possibility to be saved.
While we are talking here until now, we are sure that the concept of the congestion control is being
clear, so we do understand that congestion control is TCPs characteristic.
This can be explained further by a simple example that will help us to get a better view for this
subject.
During a normal transmission of the data packet from host A to host B, for a number of bytes we have
taken a ACK but for some of others bytes happens that their ACK is becoming late for a while.
Meanwhile a sender can still send packet data under supposition that before datas configurations are
going to come in moments.
But now TCP use congestion control, which is used to control the number of data packet sent and not
being acknowledged.
This control specifies a number in which is based on, and is used to know the number of data packet
that we can sent without getting a ACK form them, this specified number we call Congestion Window.
With this number that is decided we degrees the possibility of losing data. But here is our question.
How much this threshold should be?
If this number is little, then we do not posses good use of link, the reason is that the number of data
that can pass through is small.
In contrary if we put this number larger one, this threshold would cause larger data place reserved in
buffer, but this can result in data loss too, and we do not need this. So we have to put a correct number
that will not cause these actions described above. That is the reason why this threshold is not a
constant, but is variable number, and it depends on the traffic size. So this threshold changes nonstop
during time.
This number is configured in that way that in the beginning of transmission is small and it gets longer
time by time, always tending to have all ACKs.
When those ACKs start not to come back to the sender, so the packet data start to be lost in their way
to the destination, TCP degrees this threshold until it gets the ACKs that was searching for.
When this is achieved TCP start again to increase this number, threshold or window until has the
ability to maintain with the capacity.
To be more accurate we will take an example here. We have host A and host B that we would like to
use here again. Lets suppose that the connection between them is established (handshaking procedure
is finished), and in fact packet are in their way towards network.
By the fact that application process, host A, want to send data using the TCP protocol, this will
maintain Congestion control in this way.
Divide the streams in segments, and send only the first segment in network, (his congestion window
has one segment). Then wait for ACK for the first segment. So here it comes ACK for the first
segment, and host A send another two segments too( his congestion window now has 2 segments), and
after their ACKs reach destination in the A host, then host A send another four segments, (his
congestion window now is four) and wait. Fig.1.22.
As a conclusion, we can say that the Congestion window is growing in exponential way. And this will
continue growing in exponential way until the window congestion will reach the threshold, then it
stops growing like this. Anyway it will not stop growing all, but now it will grow in linear way.
Faqja22 / 29
Because, when it comes to the point that the TCP has passed the threshold, the congestion window
will free place just one by one, so when the destination host send back an ACK to the sender, the
window congestion will have a free place.
The TCP congestion window (cwnd) controls the number of packets/bytes that a TCP flow may have
in the network at any time. A bulk application will always have data available to transmit. The rate it
sends is therefore limited by the maximum permitted by the receiver and congestion windows. In
contrast, a variable-rate application may experience periods when the sender is either idle or is unable
to send at the maximum permitted rate. This latter case is called application-limited. [GFIB 2011]
Faqja23 / 29
If we put all those that we have said until in a graphical view, we can see the grow ness completely
exponential in the beginning. Then we can see the linear grow after the first threshold, then again the
exponential grow which differ very little with the previous linear.
So here we can make an approximation, and take the last grow linear too.
The first phase that is the face with exponential grown, we call slow start (the phase that data start to
flow). After the slow start, it comes the normal grown that we call additive. So both of them we call
additive-increase, multiplicative decrease (AIMD) algorithm that is implemented by TCP protocol.
This procedure we know like Tahos algorithm.
For the same reason is used Renos algorithm but the last one (Reno) implements fast retransmission
mechanism too.
What is fast retransmission mechanism?
Fast retransmission avoids having TCP wait for a timeout to resend lost segments. So when the sender
send packet and the receiver sends three times ACK, the sender understand that the packet after this
ACK has lost and send this back again.
There are different congestion control algorithm but TCP uses Renos one.
Faqja24 / 29
Command or Action
enable
Purpose
Enter your password if prompted.
configure terminal
ip tcp path-mtu-discovery
[age-timer {minutes |
infinite}]
ip tcp selective-ack
ip tcp timestamp
ip tcp ecn
10
7
8
Faqja25 / 29
Conclusion
In this project we have tried to explain shortly Socket as a connection between application and transfer
layers, and TCP as a successful protocol in TCP/IP suit.
As we have promised in the beginning of seminar, we have tried to explain TCP protocol in a way
which, even for the reader who is not very familiar with such things, will find something interesting,
first to understand and then learn too. But, in the other hand, this doesnt mean that the reader, who is
familiar with computer network, couldnt profit anything from this project.
We have started this project with an introduction, in which we talked about the protocols of different
layers in general, and their logic of performing their tasks. Continuing with description of interface
between two highest layers, which is called Socket and its important role.
Next, we explained TCP protocol in some details. Starting with what does the TCP protocol do with
data packets, how does it realize the connection between processes in different hosts?, then describing
the techniques which TCP use to realize a reliable data transfer (especially retransmission techniques),
which is one of the most important properties of TCP.
Finally, we treated some of the problems of these communications, and some of the mechanisms to
manage these, such as flow control and congestion control.
To sum up if the data are sent by TCP, it is absolutely sure that these data will go from source to
destination uncorrupted and in the right order.
If we dont add anything else after this sentence, it can be predicted that TCP is an ideal solution for
communication. Unfortunately, this is wrong.
Always by the project, it can be seen that the techniques which are used by TCP, exactly those
techniques with which is achieved reliable data transfer, produce delays and other problems like this.
These problems perhaps cannot be significant to transfer data, but surely these are absolutely
unbearable for audio and video content transfer (especially in real time communication). For these
reasons, TCP is not used in such forms of communication, and now the other rival, UDP comes to
scene.
But in our opinion, we think that the grown of hardware power, which has caused the development of
software possibility and other improvements too, will soon cause for TCP to overcome this problem.
By reaching the bit rate which is happening time by time, improvement in physical layer, we are
optimistic that TCP will soon perform with reliable and very fast data transfer.
Faqja26 / 29
Bibliography
[JKKR 2010]
[GFIB 2011]
[CIS 2011]
[IBM 2001]
[MC 2003]
[OReilly 1999] Craig Hunt, TCP/IP Network Administration, O'Reilly & Associates, 1999
[BFSF 2007]
[MN 1998]
[SM 2000]
[SV 2002]
[BH 2001]
[NS 2006]
[KC]
[RFC 793]
Faqja27 / 29
Appendix 1
Abbreviations
AIMD
API
DNS
ECN
ECN
FTP
HTTP
IBM
IP
ISN
MSS
MTU
OS
OSI
RFC
RTT
SMTP
TCP
UDP
WAN
Faqja28 / 29
Appendix 2
List of Figures
Number
1.1
1.2
2.1
2.2
2.3
2.4
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
3.10
3.11
3.12
2.13
3.14
3.15
3.16
3.17
3.18
Description
TCP/IP Protocol layers
Communication
Socket address
Establishment of path for two-way communication between a client and server
Application layers and the interaction with socket
Socket mechanism
Connection Oriented protocol
Three way handshake
Streaming transportation between processes
TCP segments and buffers
TCP segment structure
Connection principles
Active and Passive open
TCP data stream
Double packet at host B
ACK2 arrive in ACK1 timer
ACK2 has arrived before ACK1
The retransmission of three packets
Recivere window and reciever buffer
TCP - Window principle applied to TCP
Congestion control
Exponential increase of window congestion
Evolution of TCP's congestion window
The termination of connection
Faqja29 / 29