Transmission Control Protocol (TCP) is a connection-based protocol that ensures reliable transmission across networks, delivering data in sequence without errors, loss, or duplication. Use TCP for applications that require a reliable stream of data between programs running on different computers or different targets within a system.
You can use TCP to send datagrams between a client and a server. A datagram is a basic data transfer packet that contains the data you want to transmit and a header that indicates the source and destination address.
Unlike in UDP network communication, TCP clients and servers must establish a connection before transferring data. Establishing a connection involves listening for a connection on the server and opening a connection on the client at the port where the server is listening. After establishing a connection, the client can reliably send commands to and receive responses from the server. If you don't need highly reliable network communication and want to transfer data with lower latency, you can use UDP.