TCP scenarios

Three-way handshaking.

Active open (client connects)

Step 1: connect() sends SYN, see here

Step 2: receives SYN+ACK from server, sends ACK.

Passive open (server accepts)

First, call bind() and listen() to setup the server.

Step 1: Receives SYN from client, sends SYN+ACK

Step 2: Receives ACK from client

Then we can accept().