Netcode is tricky, but it's a solved problem (in terms of practical use). There are many first class examples to base your own work off of.