1

I have the following query about the tcp handshake.

To establish a connection the server must send a packet with SYN flag to 1 Then the server replies with a SYN,ACK flag to 1 , and afterwards the host (client) replies with ACK flag to 1 and SYN 0.

But to terminate a connection does the host send first termination or the server? Also if its the server is does the server send ACK , FIN to 1 and host replies with ACK 1 and FIN 0?

1
  • 1
    Either one can end the connection.
    – Ron Trunk
    Commented May 19, 2019 at 14:38

2 Answers 2

3

TCP does not have clients or servers, that is an application concept. TCP creates peer connections. From the application perspective, either the client or the server could request a connection with the other party, depending on how the application is architected. A server application provides a service to a client application. TCP neither knows nor cares which is a server or client.

In such a peering arrangement, either party can request disconnection. That really depends on how the application or service works. Unfortunately, questions about applications and protocols above OSI layer-4 are off-topic here.

For more information about how TCP operates, you can refer to RFC 793, Transmission Control Protocol, and there is Section 2.7. Connection Establishment and Clearing.

2
  • im asking because i had a question on a paper asking: packet captured on wireshark has the FIN flag set to 1 : the question was if its from client to server or server to client how is this possible?
    – R AND B
    Commented May 19, 2019 at 14:47
  • That is one reason that all "education, certification, or homework" questions are explicitly off-topic here. We have no idea what was taught in the class (there are many things taught with which most network engineers would disagree), so we cannot tell you what is correct for the class. We can only explain what really happens, and we can explain protocol theory. There are cases where clients initiate connections with servers, and there are also cases where servers initiate connections with clients. The same holds true for disconnections.
    – Ron Maupin
    Commented May 19, 2019 at 14:52
-1

Let, Computer A will be our transmitting computer and computer B will be our receiving computer.

To start the process off, computer A sends a TCP segment to computer B with this SYN flag set. This is computer A's way of saying, "Let's establish a connection and look at my sequence number field, so we know where this conversation starts."

Computer B then responds with a TCP segment, where both the SYN and ACK flags are set. This is computer B's way of saying, "Sure, let's establish a connection and I acknowledge your sequence number."

Then computer A responds again with just the ACK flag set, which is just saying, "I acknowledge your acknowledgment. Let's start sending data."

This exchange involving segments that have SYN, SYN/ACK, and ACK sets, happens every single time a TCP connection is established anywhere. And is so famous that it has a nickname. The three-way handshake.

A handshake is a way for two devices to ensure that they're speaking the same protocol and will be able to understand each other. Once the three-way handshake is complete, the TCP connection is established.

Three-way handshaking

Once one of the devices involved with the TCP connection is ready to close the connection, something known as a four-way handshake happens.

The computer ready to close the connection sends a FIN flag, which the other computer acknowledges with an ACK flag.

Then, if this computer is also ready to close the connection, which will almost always be the case. It will send a FIN flag.

This is again responded to by an ACK flag.

enter image description here

1
  • Each ACK acknowledges the SYN sequence initialization of the connection partner. There's no "ACK for ACK". Also, the connection termination can use a three-way FIN - ACK/FIN - ACK like with initialization.
    – Zac67
    Commented Mar 3, 2022 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.