0% found this document useful (0 votes)
70 views2 pages

Understanding Basic TCP Operations

Basic TCP operation

Uploaded by

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

Understanding Basic TCP Operations

Basic TCP operation

Uploaded by

tsegay.cs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Basic TCP operation

[Link] /2012/06/06/basic-tcp-operation/

The main purpose of TCP is error recovery and flow control. TCP is a connection-oriented protocol. It means that
before sending any data it establishes connection and terminates it upon completion.

During connection establishment server and client agree upon


sequence and acknowledgment numbers. Implicitly client also
notifies server of its source port. Sequence is a characteristic of
TCP data segment. Sequence starts with a random number and
then each time a new packet is sent, sequence is incremented
by the number of bytes sent in the previous TCP segment.
Acknowledgment segment is almost the same but from the
receiver side. It does not contain data and is equal to sender’s
sequence number incremented by the number of bytes received
(you will see example below). ACK segment acknowledges that host has received sent data.

Client-server handshake is performed in three steps:

1. Client sends packet to the server with the SYN flag set, indicating that it’s willing to establish a connection.
Client sets its sequence to a random number and sends the segment to the server.
2. Server acknowledges that it agrees to establish connection, sets its sequence to a random number,
acknowledgment to the client sequence + 1 and send them to the client.
3. In the third message client sets its acknowledgment to the server’s sequence + 1 and send back to the
server.

Now when both client and server know each other’s sequence and
acknowledgment numbers, they can start sending data. Here it’s
important to point out that TCP uses “windows” to send data. Window
essentially is a number of bytes host can send before it receives
acknowledgment from the recipient. Lets say window equals 3000 and
server sends three segments 1000 bytes each. Initially we pick random
SEQ number which equals to 1000 and increment it by 1000, which is the
segment size, with each next segment. When client has received all three
packets it answers with the ACK equal to the last SEQ number + size of
the last packet. And so on. If no errors occur receiver usually increases its
window.

Finally, when PC1 wants to close the connection it sends a FIN segment.
PC2 on the opposite side notifies the application that the connection is
closing. But since it takes some time for the application to complete its
operation, PC2 sends an ACK to the PC1, to notify it of an agreement to
finish the connection. Otherwise after a timeout PC1 will continue to
retransmit the FIN segment thinking that it has been lost. When
application is terminated PC2 sends its FIN segment, PC1 replies with ACK and connection is closed.

PS: All rights to the pictures go to Wendell Odom

1/2
2/2

Common questions

Powered by AI

TCP ensures reliable data transmission through error recovery and flow control. It is connection-oriented, meaning it establishes a connection before sending any data, ensuring both sides agree on sequence and acknowledgment numbers. The client's sequence initially starts with a random number, and the sequence and acknowledgment numbers are incremented as data packets are sent and received. The three-step handshake process between client and server establishes these numbers. Additionally, TCP uses a 'window' to manage the flow, where a sender can transmit a set number of bytes before needing an acknowledgment from the receiver. If packets are lost or errors occur, the windows are adjusted, and retransmissions can occur if necessary .

When a TCP connection is terminated, it follows a process that involves the exchange of FIN and ACK segments. The initiating side sends a FIN segment indicating it wants to close the connection. The receiver then sends an ACK segment back, acknowledging the request, but delays its FIN segment until its application is ready. Once the application completes, the receiver sends its FIN segment, and the original sender completes the closure by sending a final ACK. This process is important to ensure graceful disconnection and that both parties have finished their data exchange to prevent data loss or corruption .

The initial random sequence number is a security feature that makes TCP connections more resistant to attacks. By making the sequence number unpredictable, it prevents attackers from hijacking a session by guessing the sequence number, which is essential for inserting malicious data into a TCP stream. Additionally, it prevents problems with replay attacks, where attackers resend old segments to disrupt communication or gain unauthorized access .

Sequence numbers in TCP identify the order of bytes sent from one computer to another to help put the data back together in the correct order if segments arrive out of sequence. The sequence starts at a random number chosen by the sender. Acknowledgment numbers are sent by the receiver to confirm receipt of these sequences, indicating the next sequence number they expect to receive. This ensures that all data has arrived correctly and allows retransmission if packets are missing .

The TCP FIN segment plays a vital role in the orderly closing of a connection. It signals that a connection is ready to be closed, ensuring that both parties have completed data transmission. Without it, connections could be abruptly terminated, resulting in data loss or corruption if one party stops sending data before the other is ready. The FIN segment ensures that all data has been properly received and acknowledged before closure, supporting the integrity and reliability of the session termination process .

TCP 'windows' help mitigate network congestion by controlling the rate of data flow between sender and receiver. The window size, which can be adjusted dynamically, limits the number of unacknowledged packets in transit, helping to balance data flow according to network conditions. By adapting the window size based on packet loss or acknowledgment, TCP can prevent overflow in routers and switches. Challenges include correctly estimating the optimal window size, especially in varying network conditions, to avoid underutilization or exacerbated congestion .

TCP's 'window' size is determined by the receiver and indicates the amount of data that can be sent before an acknowledgment is required. It helps in controlling the flow of data between sending and receiving machines to ensure that the receiver's buffer does not overflow. Larger window sizes can lead to higher throughput, as more data segments can be sent before requiring an acknowledgment, but they increase the risk of congestion. Conversely, smaller window sizes require more frequent acknowledgments, which can limit data throughput especially over high-latency networks .

The TCP three-way handshake process is essential for establishing a reliable connection between a client and server. It involves three steps: 1) The client sends a segment with the SYN flag set, indicating a connection request, along with an initial sequence number. 2) The server responds with a SYN/ACK segment, acknowledging the client's sequence number and providing its own initial sequence number. 3) The client sends an ACK segment acknowledging the server's sequence number. This handshake ensures both parties have agreed upon initial sequence numbers and are ready to begin communication .

Starting sequence numbers with random values is crucial for security and data integrity. The randomness helps protect against prediction attacks, where an attacker could guess the sequence numbers and potentially hijack a session. Random initial sequence numbers also ensure that previously transmitted data cannot be resent and misinterpreted as new data, adding a layer of protection against duplicate data segments being misprocessed .

Acknowledgment segments in TCP play a critical role in ensuring reliable data transmission. They confirm receipt of data segments by sending back the sender’s sequence number incremented by the total bytes received. This ensures that each segment is accounted for, allowing the sender to know which segments require retransmission. Positive acknowledgment guarantees that data received is correct, and if errors occur, the absence of acknowledgment prompts retransmission, thus maintaining connection integrity. Acknowledgments also contribute to the flow control mechanism by allowing window adjustments based on the network conditions .

You might also like