Welcome to Network Programming
Computer Networks taught you how the Internet works — layers, protocols, headers. Network Programming teaches you to write the programs at both ends of the wire: clients, servers, daemons, ping, traceroute, even packet sniffers. The toolkit is the sockets API — the C interface (born in 4.2BSD UNIX, 1983) that still underlies every networked program: browsers, game servers, Node.js, Python's socket module, all of them.
The guiding textbook tradition for this paper is W. Richard Stevens' UNIX Network Programming — the lessons follow its path and its famous client/server examples.
The journey of this course
How this course is organised
| Syllabus block | Lessons that cover it |
|---|---|
| OSI model, Unix standards, TCP/UDP, connection establishment, buffer sizes, standard services | Unit 1 → "Protocol Foundations" |
| Socket address structures, value-result arguments, byte ordering | Unit 1 → "Socket Address Structures & Byte Ordering" |
| socket, connect, bind, listen, accept, fork/exec, concurrent servers, close | Unit 1 → "Elementary TCP Sockets" |
| TCP echo client/server, signal handling, server crash/reboot scenarios | Unit 2 → "The TCP Echo Client–Server & Its Failure Modes" |
| Elementary UDP sockets, lost datagrams, no flow control, outgoing interface | Unit 2 → "Elementary UDP Sockets" |
| I/O models, select, poll, shutdown, batch input | Unit 2 → "I/O Multiplexing" |
| getsockopt/setsockopt, socket states, all option levels | Unit 2 → "Socket Options & Advanced I/O" (first half) |
| Socket timeouts, recv/send flags, readv/writev, recvmsg/sendmsg, ancillary data | Unit 2 → "Socket Options & Advanced I/O" (second half) |
| DNS, gethostbyname, resolver, IPv6 functions, uname | Unit 3 → "Name & Address Conversions" |
| Daemons, syslog, daemon_init, inetd | Unit 3 → "Daemon Processes & the inetd Superserver" |
| Broadcasting, unicast vs broadcast, race conditions | Unit 3 → "Broadcasting" |
| Multicasting, mcast_join, MBone, SNTP | Unit 3 → "Multicasting & SNTP" |
| Raw sockets, ping, traceroute, ICMP daemon | Unit 4 → "Raw Sockets" |
| BPF, DLPI, SOCK_PACKET, libpcap, UDP checksum | Unit 4 → "Datalink Access" |
| Terminal line disciplines, pseudo-terminals, rlogin, RPC transparency | Unit 4 → "Remote Login & RPC Transparency" |
| Lab programs (sockets in C) | "Lab Practicals" lesson at the end |
Prerequisites
| You should know | Why |
|---|---|
C programming (pointers, structs, fork) | the entire API is C |
| TCP/IP basics: IP addresses, ports, the 3-way handshake | we now drive these from code |
| Basic Unix/Linux shell | compiling, running client+server in two terminals |
How to study this course
- Type and run every program. A Linux machine (or WSL on Windows) and
gccare all you need. One run of an echo server teaches more than three readings. - Keep two terminals open — client on the left, server on the right — and watch both sides of every experiment.
- Use the tools as you learn the calls:
netstat -an/ss -tanto see socket states,tcpdump/Wireshark to watch the segments your code generates. - Draw the call sequence for every program — the socket-function "ladder diagrams" in these lessons are the exact diagrams exam answers want.
- Memorise the failure-mode stories (Unit 2): what the client sees when the server crashes, vs reboots, vs is unreachable — favourite viva and theory questions.
What end-term questions in this paper look like
Network Programming questions come in four recognisable shapes — knowing the shape tells you how to structure the answer:
| Question shape | Example | What a full-marks answer contains |
|---|---|---|
| "Explain function X" | "Explain accept() with its arguments" | full prototype, each argument's role and direction, return value, one error case, 3–4 line code fragment |
| "Diagram + walkthrough" | "Explain TCP connection establishment" | the sequence/ladder diagram, segment names (SYN, SYN-ACK, ACK), which socket call blocks where, state names |
| "Compare A and B" | "Compare select and poll" / "TCP vs UDP" | a table of 5–7 rows, then 2–3 sentences saying when you'd choose which |
| "Scenario / what happens if" | "What does the client observe when the server host crashes?" | timeline of events on the wire, the errno the application finally sees, and the fix (timeout / keep-alive / select) |
Two writing habits that consistently earn marks: always give the prototype before discussing a function (examiners scan for it), and always name the errno in failure scenarios — "the call fails" earns half of what "connect returns −1 with errno ECONNREFUSED because an RST arrived" earns.
The vocabulary you must own before Unit 1
A quick glossary — every term below is defined properly in its lesson, but you should recognise them from day one:
- descriptor (fd): small integer naming an open file/socket in a process — the currency of the whole API.
- segment / datagram / frame: the protocol unit at TCP / UDP-IP / link layer respectively. Using the right word signals competence.
- well-known vs ephemeral port: server's fixed advertised port vs the kernel-chosen temporary client port.
- blocking call: one that puts the process to sleep until the event happens (default for accept, read, recvfrom...).
- half-close: closing one direction of a TCP connection while the other keeps flowing (
shutdown). - RST vs FIN: abortive reset vs orderly goodbye — the difference drives half of Unit 2's failure stories.
Self-check before you begin
- Which layer of the OSI model does the sockets API expose to your program, and which layers does your program itself implement?
- Name the three pieces of information that uniquely identify one end of a TCP connection, and the four that identify the whole connection.
- Why does a TCP application need two terminals (client + server) to test, while a UDP experiment can sometimes fake it with one?
- What tool shows you the TCP state (LISTEN, ESTABLISHED...) of every socket on your machine right now?
If question 2 made you pause — (IP, port) per end; (client IP, client port, server IP, server port) for the connection, the famous 4-tuple — you are exactly where this course expects you to start.