TCP's three-way handshake
A client and a server agree on a connection with three packets: SYN, SYN-ACK, ACK. Choose which packet gets lost first.
A pragmatic compromise
TCP does not solve the generals' problem, it sidesteps it
After three packets the server knows that the client knows that the server got its request. That is three levels, not infinity: the client that sent the ACK does not know whether it arrived. TCP (RFC 793, 1981; now RFC 9293) simply does not require certainty. The client treats the connection as open right after its ACK, and if the ACK was lost, the server repeats SYN-ACK after a timeout. Mistakes can happen, but they are fixed by retrying, not by logic.
Where common knowledge is what you need, you make a public statement, like the visitor on the island. Central banks announce rate decisions at a press conference for everyone at once rather than phoning each bank: what matters is that everyone knows that everyone else knows too. And in Andersen's tale "The Emperor's New Clothes" (1837) a child says out loud what everyone saw. After his words the naked emperor is seen by all together, and nobody can pretend any more.