couldn't we just communicate without this handshake |
TCP is a stateful protocol. Both the client and the server need to set up data structures to keep track of the state of the connection to handle packet retransmission, etc.
but why do we need to listen?? |
Because a connection needs to be established before packets can be sent, and in turn a connection is needed because TCP needs to be able to guarantee that either the packet was received by the destination, or that it was lost and this fact must be notified to the sender.
couldn't we just send a packet from computer B to computer A without listening? |
If there's no one listening, what's the point of sending data? I mean, even if there's no one "listening" in the TCP sense, you still need a program on the receiving end that will pull the data from the OS's buffer.
Yes, you can send UDP datagrams or even raw IP or Ethernet packets to some IP or MAC address with zero guarantee that the data is being received by anyone (unless you've already established an implicit connection by external channels, such as through TCP, or by directly controlling both ends of the communication).
Can a TCP connection be established between two clients? instead of one server and one client and if so how? |
No. In TCP, one of the participants is the server and it listens for incoming connections, and the other is the client and it opens a connection to a server.
Any connection-based protocol will have the same limitation. To establish a connection, someone first needs to be listening for it and someone else needs to request opening it.