A Hacker School project explores TCP by building a miniature network stack in Python with Scapy, aiming to request and retrieve a webpage without relying on the operating system’s TCP implementation. The account explains the basic handshake - SYN, SYN-ACK, ACK - and why TCP sequence numbers and acknowledgments track delivered data and allow missing packets to be resent. The first attempt fails in an unexpected way: after the program sends a SYN and receives a SYN-ACK, the computer’s kernel sends a reset because it sees a connection it did not initiate. To prevent this interference, the experiment uses ARP spoofing and a different apparent IP address, so the kernel ignores the incoming traffic and the Python program can complete the handshake.
After that, getting Google’s HTML requires assembling an HTTP GET, handling multiple response packets, correcting sequence-number bugs, and closing the connection. The resulting implementation is fragile but works: a curl-like program retrieves a page about a quarter of the time. Packet captures also reveal that the server sends data faster than the Python program appears to acknowledge it; the original explanation blames Python’s speed, though the author later notes that diagnosis may be wrong. The larger lesson is that TCP is far more involved than its basic handshake suggests, yet a rough implementation can still communicate with real servers. Writing it in Python is presented as a valuable, enjoyable way to learn networking, not as a practical approach to production TCP software.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.