Couldn't find anywhere else to put this for the question asker, but here's a set of blog posts that dive into how to code a network stack using UDP and coding it for reliability. The articles' author has also open sourced a c-library networking layer, reliability layer, and game networking controller than can handle up to 64 players with all the modern conveniences like encryptions. It's very educational.

Gaffer On Games Blog Posts
Github for the libraries