TCP (Transmission Control Protocol) is a connection-oriented transport layer protocol that ensures reliable, ordered, and error-checked data transmission.

Elaboration:

  • Establishes a three-way handshake before sending data.
  • Uses flow control, error checking, and retransmission mechanisms.
  • Works on ports like HTTP (80), HTTPS (443), FTP (21), and SMTP (25).

Example:

Web browsing, file downloads, and secure email transmissions rely on TCP.

Code Example: (TCP Client)

pythonCopyEditimport socket

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(("example.com", 80))
client.send(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
print(client.recv(1024).decode())
client.close()