TCP provides flow control between a sender and receiver to prevent buffer overflows. It works by having the sender maintain a receive window size, which indicates the available free buffer space at the receiver. The sender ensures it doesn't send more data than the receive window size allows. TCP also uses a three-way handshake to establish connections between a client and server. This involves the client sending a SYN packet, the server responding with a SYN-ACK, and the client replying with an ACK to open the connection. Connections are closed using a four-step process where each side sends a FIN packet and acknowledges the other's FIN.