See [RFC 9293](https://datatracker.ietf.org/doc/html/rfc9293) for more on this topic. See [[Transmission Control Protocol (TCP)]] for more on the TCP protocol itself. 1. The connecting terminal/machine, sends a TCP request to the target server with a SYN flag set. 2. The server acknowledges this packet with a TCP response containing the SYN and ACK flag. 3. The terminal completes the handshake by sending a TCP request with the ACK flag set. 4. Once the connection is established, data such as bytes if a file, are sent via the DATA message. 5. FIN packet is used to properly/cleanly close the connection (the client will reply to the FIN with an ACK). If a port is **abruptly** closed the server will instead send a TCP packet with the RST (Reset) flag set. During the Three Way Handshake, the client will send the SYN with an initial sequence number (ISN) in order to synchronize with. Lets say 0. Then the server will send the SYN/ACK with its ISN lets say 1000 for the SYN and it will acknowledge the clients ISN (which was 0) via the ACK. The client will ACK the servers ISN (1000 for this example) and provide its ISN+1.