networking

Fixing the Internet for Games

What we're doing at my new startup [Network Next](https://networknext.com) šŸš€

Networked Physics in Virtual Reality

Introduction About a year ago, Oculus approached me and offered to sponsor my research. They asked me, effectively: “Hey Glenn, there’s a lot of interest in networked physics in VR. You did a cool talk at GDC. Do you think could come up with a networked physics sample in VR that we could share with devs? Maybe you could use the touch controllers?” I replied “F*** yes!” cough “Sure. This could be a lot of fun!

Why can't I send UDP packets from a browser?

Premise In 2017 the most popular web games like agar.io are networked via WebSockets over TCP. If a UDP equivalent of WebSockets could be incorporated into browsers, it would greatly improve the networking of these games. Background Web browsers are built on top of HTTP, which is a stateless request/response protocol initially designed for serving static web pages. HTTP is built on top of TCP, a low-level protocol which guarantees data sent over the internet arrives reliably, and in the same order it was sent.

Client Server Connection

Introduction Hi, Iā€™m Glenn Fiedler and welcome to Building a Game Network Protocol. So far in this article series we’ve discussed how games read and write packets, how to unify packet read and write into a single function, how to fragment and re-assemble packets, and how to send large blocks of data over UDP. Now in this article we’re going to bring everything together and build a client/server connection on top of UDP.

Reliable Ordered Messages

Introduction Hi, Iā€™m Glenn Fiedler and welcome to Building a Game Network Protocol. Many people will tell you that implementing your own reliable message system on top of UDP is foolish.Ā After all, why reimplement TCP? But why limit ourselves to how TCP works? But thereĀ are so many different ways to implement reliable-messages and most of them workĀ nothing like TCP! So let’s get creative and work out how we can implement a reliable message system that’s better and more flexible than TCP for real-time games.

Sending Large Blocks of Data

Introduction Hi, Iā€™m Glenn Fiedler and welcome to Building a Game Network Protocol. In theĀ previous articleĀ we implemented packet fragmentation and reassembly so we can send packets larger than MTU. This approach works great when the data block you’re sending is time critical and can be dropped, but in other cases you need to send large blocks of quickly and reliably over packet loss, and you need the data to get through.

Packet Fragmentation and Reassembly

Introduction Hi, Iā€™m Glenn Fiedler and welcome to Building a Game Network Protocol. In theĀ previous articleĀ we discussedĀ how to unify packet read and write into a single serializeĀ function and added a bunch of safety features to packet read. Now we are ready to start putting interesting things in our packets and sending them over the network, but immediately we run into an interesting question:Ā how big should our packets be?

Serialization Strategies

Introduction Hi, Iā€™m Glenn Fiedler and welcome to Building a Game Network Protocol. In the previous article, we created a bitpacker but it required manual checking to make sure reading a packet from the network is safe. This is a real problem because the stakes are particularly high - a single missed check creates a vulnerability that an attacker can use to crash your server. In this article, we’re going to transform the bitpacker into a system where this checking is automatic.

Reading and Writing Packets

Introduction Hi, Iā€™m Glenn Fiedler and welcome to Building a Game Network Protocol. In this article we’re going to explore how AAA multiplayer games like first person shooters read and write packets. We’ll start with text based formats then move into binary hand-coded binary formats and bitpacking. At the end of this article and the next, you should understand exactly how to implement your own packet read and write the same way the pros do it.

State Synchronization

Introduction Hi, I’m Glenn Fiedler and welcome to Networked Physics. In the previous article we discussed techniques for compressing snapshots. In this article we round out our discussion of networked physics strategies with state synchronization, the third and final strategy in this article series. State Synchronization What is state synchronization? The basic idea is that, somewhat like deterministic lockstep, we run the simulation on both sides but, unlike deterministic lockstep, we don’t just send input, we send both input and state.

Snapshot Compression

Introduction Hi, I’m Glenn Fiedler and welcome to Networked Physics. In the previous article we sent snapshots of the entire simulation 10 times per-second over the network and interpolated between them to reconstruct a view of the simulation on the other side. The problem with a low snapshot rate like 10HZ is that interpolation between snapshots adds interpolation delay on top of network latency. At 10 snapshots per-second, the minimum interpolation delay is 100ms, and a more practical minimum considering network jitter is 150ms.

Snapshot Interpolation

Introduction Hi, I’m Glenn Fiedler and welcome to Networked Physics. In the previous article we networked a physics simulation using deterministic lockstep. Now, in this article we’re going to network the same simulation with a completely different technique: snapshot interpolation. Background While deterministic lockstep is very efficient in terms of bandwidth, it’s not always possible to make your simulation deterministic. Floating point determinism across platforms is hard. Also, as the player counts increase, deterministic lockstep becomes problematic: you can’t simulate frame n until you receive input from all players for that frame, so players end up waiting for the most lagged player.

Deterministic Lockstep

Introduction Hi, I’m Glenn Fiedler and welcome to Networked Physics. In the previous article we explored the physics simulation we’re going to network in this article series. In this article specifically, we’re going to network this physics simulation using deterministic lockstep. Deterministic lockstep is a method of networking a system from one computer to another by sending only the inputs that control that system, rather than the state of that system.

Introduction to Networked Physics

Introduction Hi, I’m Glenn Fiedler and welcome to the first article in Networked Physics. In this article series we’re going to network a physics simulation three different ways: deterministic lockstep, snapshot interpolation and state synchronization. But before we get to this, let’s spend some time exploring the physics simulation weā€™re going to network in this article series: Your browser does not support the video tag. Here Iā€™ve setup a simple simulation of a cube in the open source physics engine ODE.

Floating Point Determinism

Introduction Hi, I’m Glenn Fiedler and welcome to Networking for Game Programmers. Lately I’ve been doing some research into networking game physics simulations via deterministic lockstep methods. The basic idea is that instead of synchronizing the state of physics objects directly by sending the positions, orientations, velocities etc. over the network, one could synchronize the simulation implicitly by sending just the player inputs. This is a very attractive synchronization strategy because the amount of network traffic depends on the size of the player inputs instead of the amount of physics state in the world.

What Every Programmer Needs To Know About Game Networking

Introduction Hi, I’m Glenn Fiedler and welcome to Networking for Game Programmers. Have you ever wondered how multiplayer games work? From the outside it seems magical: two or more players sharing a consistent experience across the network like they actually exist together in the same virtual world. But as programmers we know the truth of what is actually going on underneath is quite different from what you see. It turns out it’s all an illusion.

Reliability and Congestion Avoidance over UDP

Introduction Hi, I’m Glenn Fiedler and welcome to Networking for Game Programmers. In the previous article, we added our own concept of virtual connection on top of UDP. In this article weā€™re going to add reliability, ordering and congestion avoidance to our virtual UDP connection. The Problem with TCP Those of you familiar with TCP know that it already has its own concept of connection, reliability-ordering and congestion avoidance, so why are we rewriting our own mini version of TCP on top of UDP?

Virtual Connection over UDP

Introduction Hi, I’m Glenn Fiedler and welcome to Networking for Game Programmers. In the previous article we sent and received packets over UDP. Since UDP is connectionless, one UDP socket can be used to exchange packets with any number of different computers. In multiplayer games however, we usually only want to exchange packets between a small set of connected computers. As the first step towards a general connection system, we’ll start with the simplest case possible: creating a virtual connection between two computers on top of UDP.

Sending and Receiving Packets

Introduction Hi, I’m Glenn Fiedler and welcome to Networking for Game Programmers. In the previous article we discussed options for sending data between computers and decided to use UDP instead of TCP for time critical data. In this article I am going to show you how to send and receive UDP packets. BSD sockets For most modern platforms you have some sort of basic socket layer available based on BSD sockets.

UDP vs. TCP

Introduction Hi, I’m Glenn Fiedler and welcome to Networking for Game Programmers. In this article we start with the most basic aspect of network programming: sending and receiving data over the network. This is perhaps the simplest and most basic part of what network programmers do, but still it is quite intricate and non-obvious as to what the best course of action is. You have most likely heard of sockets, and are probably aware that there are two main types: TCP and UDP.

Networked Physics (2004)

Introduction Hi, I’m Glenn Fiedler and welcome to Game Physics. In the previous article we discussed how to use spring-like forces to model basic collision response, joints and motors. In this article we’re going to discuss how to network a physics simulation. First Person Shooters First person shooter physics are usually very simple. The world is static and players are limited to running around and jumping and shooting. Because of cheating, first person shooters typically operate on a client-server model where the server is authoritative over physics.