To establish a connection between two computer system through TCP protocol, TCP use three way handshake to establish the connection. Three way handshake is used to create a tcp socket connection. The Tcp handshake is look like this.


As shown in the above diagram. A computer want to establish a connection with another computer. The computer send SYS packet to the computer/server and request the server for a connection. as soon as the server receive the SYS packet,it reply back with SYS/ACK and tell the host that it has received his SYS request. at last client send the ACK and the three way handshake is completed,Now the data is transferred.

TCP FLAGS

SYS -: The SYN, or Synchronisation flag is the first tcp flag used to start a communication with server or computer.

ACK -: The ACK or Acknowledgment flag is used to Acknowledge the packet. which mean a packet is received.

FIN -: FIN flag is used to finish the connection. when FIN flag is send that mean data has been transferred and no data is left to be sent and close the connection with the server/computer.



URG -: URG mean urgent, when a client send URG flag which mean data is urgent. and tell the server to start the connection quickly.

PSH -: The PSH flag, which stands for Push is somewhat similar to the URG flag and tells the receiver to process these packets as they are received instead of buffering them.

RST -: RST stand for reset the connection with the computer/server.