

With TCP, all data arriving at a connected socket must come from the other endpoint of the connection. Any UDP application, therefore, must be prepared to check the source address of each packet that arrives. With UDP, if a server opens a socket (the OS object, with corresponding socket address), then any client on the Internet can send to that socket, via its socket address. The connection-oriented nature of TCP warrants further explanation. Note that the connection-orientation and reliability of TCP represent abstract features built on top of the IP layer which supports neither of them.

The drawback here, however, is the overhead of setting up a new connection for each request a better application-protocol design might be to allow multiple request/reply pairs over a single TCP connection. TCP even works reasonably well for request/reply protocols, where one side sends a message, the other side responds, and the connection is closed. Examples of this include ssh or telnet, where packets are exchanged on each keystroke, and database connections that may carry many queries per second. TCP also works quite well for interactive applications where each side is sending and receiving streams of small packets.

The two endpoints open a connection, the file data is written by one end into the connection and read by the other end, and the features above ensure that the file will be received correctly. These features mean that TCP is very well suited for the transfer of large files.

Finally, TCP automatically uses the sliding windows algorithm to achieve throughput relatively close to the maximum available. TCP is reliable, in that TCP uses sequence numbers to ensure the correct order of delivery and a timeout/retransmission mechanism to make sure no data is lost short of massive network failure. TCP is connection-oriented, meaning that a connection must be established before the beginning of any data transfer. TCP is stream-oriented, meaning that the application can write data in very small or very large amounts and the TCP layer will take care of appropriate packetization. TCP is quite different in several dimensions from UDP. TCP provides a much richer functionality for sending data to (connected) sockets. As we saw in 11 UDP Transport, UDP provides simple datagram delivery to remote sockets, that is, to ⟨host,port⟩ pairs. The standard transport protocols riding above the IP layer are TCP and UDP.
