Consider the three way handshake of TCP. It is explained here.
Now the article above mentions that two sides may try to connect simultaneously and the three way handshake works fine in this case.
Can we simulate this situation using the sockets api.
what we usually code using sockets is a passive open(server) and an active open(client)?
It is possible to cause a simultaneous TCP open using the sockets API. As Nikolai mentions, it is a matter of executing the following sequence with a timing such that the initial SYNs cross each other.
Here’s how I achieved a simultaneous open using a single Linux host.
Slow down the loopback interface using netem
Run
netcattwiceThe two netcat processes connect to each other resulting in a single TCP connection
Here’s what tcpdump showed me (output edited for clarity)