惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
Y
Y Combinator Blog
月光博客
月光博客
IT之家
IT之家
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
L
LangChain Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - Franky
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
V
Visual Studio Blog
小众软件
小众软件
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Building TCP From Scratch (1/6): Why bother when TCP exists?
Bhavesh Ghan · 2026-04-27 · via DEV Community

What does the word "retransmit" actually mean? I thought I knew. I'd taken the networking class. I'd read the chapter. I could draw the slow-start curve on a whiteboard. Then I tried to write it and discovered I had no idea.

This is a series about rebuilding TCP from scratch in Java, and the parts of it I only understood after the code actually ran.

What I built

LEAP (Loss-aware End-to-end Acknowledged Protocol) is a TCP-style reliable transport I built from scratch on top of UDP. About 1,900 lines of Java. It has sequence numbers, cumulative ACKs, a sliding window, fast retransmit on three duplicate ACKs, adaptive RTO in the style of RFC 6298, slow start and AIMD congestion control with an ssthresh floor, and end-to-end SHA-256 integrity verification on every transfer.

There's a CLI:

./bin/leap receive --port 4040 --output /tmp/in
./bin/leap send myfile.bin --to localhost:4040

Enter fullscreen mode Exit fullscreen mode

And a benchmark harness that sweeps file size × loss rate × trial across LEAP and TCP.

I built this over about three weeks in March 2026, while doing my MS in CS at USC. Everything lives at github.com/bhaveshGhanchi/leap, including the protocol, CLI, benchmark harness, and plotting scripts. Each post in this series points at specific files and line numbers in that repo.

Why I bothered

A few reasons.

The first is that reading about TCP is not the same as implementing it. Stevens' TCP/IP Illustrated has roughly 200 pages on TCP. They're great pages. They didn't prepare me for writing the retransmission timer loop. The textbook says "the sender retransmits if it doesn't receive an ACK within RTO." The code has to actually handle four cases at once: the original ACK arrives normally, the ACK is late but arrives during retransmission, the ACK never arrives and you keep retransmitting, and the path is just slow rather than lossy and your RTO needs to grow without spiraling. The textbook compresses all of that into one sentence. The code can't.

The second is congestion control. Most engineers can sketch the cwnd graph: slow start ramp, then sawtooth. Far fewer can tell you what a duplicate ACK actually is at a code level, or why three of them is the magic number, or what ssthresh = max(cwnd/2, 4) does to a flow that's just hit its first loss. I couldn't have told you any of these before this project. I can now, because I had to write each one and watch what happened when I got it wrong. Which I did. Several times.

The third is measurement. Anyone can benchmark a happy path: localhost, no loss, "look how fast my code goes." The interesting question is what TCP-like protocols do at 5% loss, 10% loss, 20% loss. I wanted to see those curves with code I'd written, where I knew exactly which packet was retransmitted, why, and what the cwnd was at the moment the loss happened.

I also wanted to measure honestly, which turned out to be much harder than the implementation. Chapter 6 of this series is about how I built three different ways of simulating packet loss, two of which silently lie, and how I figured out which two.

None of this is novel. TCP Tahoe is from 1988. Van Jacobson and Mike Karels figured out the hard parts before I was born. I'm not trying to push the state of reliable transport forward. I'm trying to understand it.

Who this series is for

  • You've taken a networking class and want to see the textbook ideas as code that compiles.
  • You use TCP every day in production and want to know what's inside the syscall.
  • You're curious what "congestion window" means at line-of-code level, not at whiteboard level.
  • You like reading code with measurements attached, and writeups that admit when things didn't work.

This isn't for people looking for a production reliable-UDP library. Use QUIC. There are excellent open-source implementations like msquic, quiche, and quic-go. They have encryption, multiplexing, NAT traversal, modern congestion control, and a decade of production hardening. LEAP has none of those. It's a project I built to understand TCP.

What's coming

Six posts:

  1. Why bother when TCP exists? (this post)
  2. Sequence numbers, ACKs, and the simplest reliable protocol that works
  3. Sliding window: the trick that makes TCP fast
  4. Retransmission timers: why RTO is the hardest part
  5. Congestion control: TCP's politeness algorithm
  6. Measuring it honestly: three ways to fake packet loss, two of which lie

Each post pulls from a specific part of the LEAP repo. By the end, you'll have seen enough code to implement your own version, and enough about measurement methodology to be skeptical of anyone else's.

What I'm not claiming

LEAP is not faster than TCP. TCP wins on every benchmark in this series at every loss rate, which is fine. TCP has been optimized for thirty years and runs in the kernel. LEAP runs in userspace Java.

It's not novel either. TCP Tahoe is 1988. The interesting thing is what I learned by writing it.

It's also not production-ready. Single sender, single receiver, one file per session, no encryption, no NAT traversal, localhost-tested only. Don't put it on the internet.

How to read along

The repo is at github.com/bhaveshGhanchi/leap. The README has the full architecture: packet format, protocol design, benchmark methodology, limitations. If you read code, the entire implementation is roughly 1,900 lines of Java; you can read it in an evening before starting this series. If you'd rather read prose, this series is the slower walkthrough, with the bugs and dead ends included.

Up next

Chapter 2 is about the simplest reliable protocol that works: stop-and-wait. It works. It's also almost unusable on any real network. We'll see how unusable, and then start fixing it.