Networking in C · beginner · ~8 min
Pick the right transport protocol for the job.
TCP (Transmission Control Protocol): bytes arrive in order, with no duplicates and no loss, but possibly with delay if a packet had to be retransmitted. The kernel handles the retransmits, ordering, and flow control for you. Used by HTTP, SSH, SMTP, Git, almost everything you interact with.
UDP (User Datagram Protocol): each sendto() becomes one packet on the wire. The packet may arrive, may not arrive, or may arrive out of order. If you want reliability, you build it on top. Used by DNS, video conferencing, gaming, QUIC.
Defaults to know:
send() calls of 4 bytes might arrive as one recv() of 8.For everything in this course we use TCP unless an exercise specifically calls out UDP.
int tcp = socket(AF_INET, SOCK_STREAM, 0); /* TCP */
int udp = socket(AF_INET, SOCK_DGRAM, 0); /* UDP */
TCP = reliable, ordered byte stream (no message boundaries). UDP = best-effort datagrams (boundaries preserved, delivery not). Default to TCP.