Detail the step-by-step process of a TCP three-way handshake and how state is maintained on both the client and server.