tcp two sides trying to connect simultaneously

前端 未结 3 967
逝去的感伤
逝去的感伤 2020-12-29 09:46

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 hand

3条回答
  •  别那么骄傲
    2020-12-29 10:12

    We do passive server and active client because it's easy to understand, [relatively] easy to implement, and easy to code for. Think of a store and a customer, we'd be in one of these situations:

    • Customer goes to the store (active client), the store is open (passive server) - both are happy.
    • Customer goes to the store, the store is closed (no server listening) - no luck for the customer.
    • Store is open, no customers come - no luck for the store.
    • Store is closed and no customers come - who a cares :)

    Since the server passively waits for clients to connect it's easy to predict when a connection can take place. No pre-agreements (other then server address and port number) are necessary.

    The simultaneous open, on the other hand, is subject to connect timeouts on both sides, i.e. this has to be carefully orchestrated for connection to take place so that SYNs cross "in-flight". It's an interesting artifact of the TCP protocol but I don't see any use for it in practice.

    You can probably try simulating this by opening a socket, binding it to a port (so the other side knows where to connect to), and trying to connect. Both sides are symmetric. Can probably try that with netcat with -p option. You'd have to be pretty quick though :)

提交回复
热议问题