Game Networking


What is the best way to send data between machines? Do you use TCP sockets, UDP sockets or a mixture of both? In this article we explore this fundamental choice and decide on the best option for fast-paced action games.

Sending and Receiving Packets

This article shows how to send and receive UDP packets using BSD sockets, giving you source code that works across MacOS X, Windows and Unix.

Virtual Connection over UDP

Learn how to create your own virtual connection between two machines on top of UDP. How to detect connection, filter out packets from other machines and detect disconnection via timeout.

Reliability, Ordering and Congestion Avoidance over UDP

Learn how to implement your own reliability system on top of UDP using sequence numbers and acks. Also presented is a simple congestion avoidance algorithm.

Debugging Multiplayer Games

Explains the techniques used by professional game developers to debug multiplayer games.

What Every Programmer Needs To Know About Game Networking

A brief overview of the history of PC multiplayer games. Discover how RTS games were able to synchronize thousands of units over a 28k modem, and how first person shooters hide lag with client side prediction and latency compensation.

Floating Point Determinism

Is it possible to get exactly the same floating point result (down to the bit-level) each time a program is run? How about across debug and release builds? Across different compilers? Different CPU architectures?

If you enjoyed this article series please donate. Donations encourage me to write more articles!

108 comments on “Game Networking
  1. Pingback: Creating a simple client-server system for a game Part 1 | Talis' blog

  2. Hey Glenn and anyone interested,

    Since C11 has come out, (and I don’t like google code), I made a github for the current code and have been updating it for Windows (Linux next, mac if I can get my copy of it to work). I make abundantly clear where the project came from. As does Google code exporter.

    Glenn, you should look into the fact that all the links in the code point to and not I’ve been updating those as I go along.

  3. Pingback: First steps in creating a multiplayer game in Unity

  4. Nice article about the matter. Although I am now still sitting in font of my PC not knowing how to implement everything I have learned here so far because there are still some question left. Like for example if the network code should run in its own thread (read somewhere it shouldn’t but with no further explanation) or how to implement this exactly in an object orientated environment.
    However I realized now that networking seems to be way more ressource critical then I ever imaginennd it would. Especially on ressource critical systems like smartphones this makes it even harder to implement something good.
    So far what I have learned is that I am going to use UDP hole punching for a ‘client to client’ connection. Also fighting against cheaters is like fighting against piracy… useless.

    • Get it working on a single thread non-blocking first. If there are performance problems with that, move it to another thread as an optimization. Don’t feel you need to do it multithreaded initially.

      Next, for NAT punch through sure if you do client->client you would have to do that. So don’t :). Do client/server and have a server in a data center and no punching is required. This is the way ™. NAT punching and P2P are stupid and a waste of time.

  5. Pingback: Going through the list – Networking! | Welcome to Corné Thoes his Blog!

  6. Pingback: Gabor Heja / blog | Multiplayer gaming, part 1: Sync the future!

  7. Pingback: Development Notes | Jeremy Somer

  8. Pingback: UDP vs TCP – a follow up | 1024 Monkeys

  9. Pingback: [Перевод] Сетевое программирование для разработчиков игр. Часть 3: виртуальные соединения поверх UDP | test4

  10. Pingback: [Перевод] Сетевое программирование для разработчиков игр. Часть 3: виртуальные соединения поверх UDP » CreativLabs

  11. Pingback: Сетевое программирование для разработчиков игр. Часть 3: виртуальные соединения поверх UDP « Домик Миа

  12. Pingback: Сетевое программирование для разработчиков игр. Часть 2: прием и передача пакетов данных « Домик Миа

  13. Pingback: [Перевод] Сетевое программирование для разработчиков игр. Часть 3: виртуальные соединения поверх UDP | Malanris's site

  14. Pingback: [Перевод] Сетевое программирование для разработчиков игр. Часть 3: виртуальные соединения поверх UDP | Вести3.ру — Информационный журнал

  15. Pingback: Сетевое программирование для разработчиков игр. Часть 1: UDP vs. TCP « Домик Миа

  16. Pingback: Seikun Kambashi | Facebook Hackathon

  17. Pingback: [Перевод] Сетевое программирование для разработчиков игр. Часть 1: UDP vs. TCP | Malanris's site

  18. Hello Glenn, and thanks for your great articles! I really enjoyed them and would like to translate them to russian – so that more people could enjoy them:) Do you mind if I do this? I’ll keep all the links to the original, of course.

  19. Hi Glenn Fiedler,
    I just recently discovered your articles on networking. I have to say it is by far best I have seen. Thank you for all the time you put into this.

  20. Pingback: Multiplayer coding and the lockstep network model | Sparkrift

  21. Hi Glenn,

    I just watched your 2009 talk on your coop networking model, awesome stuff! Really got me thinking about a coop procedurally generated minecraftian open world game I’m working on. You mentioned at the end that you thought it needed ‘hardening’, has this been presented in more talks or articles since then? Also a guy came up to you and started explaining issues he’d had with a similar networking model, but the video cuts off before he explains. Would you still advocate the model from that talk? I was otherwise going to do client-server but trust the clients a lot to hide lag, but peer to peer would allow me to share AI processing cost, and means the server doesn’t need to deal with the overhead of calculating how relevant objects are for each client, maintain their network scopes, sort them constantly based on priority etc.

    • The idea of distributing the cost is still sound however these days I’d do it in a client/server topology where the server is like a database with no sim. This makes late join and host migration easy. With p2p it’s virtually impossible.

  22. Pingback: Networking for Game Programmers | Johnny Rocketpants

  23. Pingback: 8+ Caves Of Knowledge for HTML5 Gamedevlopers | Rezoner Sikorski

  24. Pingback: Client-server Application - Startup (PART 1) | Exasm

  25. Pingback: Network Programmer Blogs (especially for games) | Question and answer

  26. Pingback: Game Development Resources | Michel Rinck

  27. Pingback: Battlefield 3. Как бы уже… » Сетевые Шутеры: Как они работают

  28. Pingback: Networking: How A Shooter Shoots | Kotaku Australia

  29. Pingback: Learning Multiplayer Game Programming |

  30. Pingback: 终将游戏一生 » TCP vs UDP

  31. Have you considered putting this on the Kindle store? I hear it’s easy to do and it would be a lot nicer for me to read it there. Would easily pay $9.99 for the connivence.


  32. Thank you very much. I’m glad you enjoy them!

    I find that many things which seemed complicated are usually easy once somebody explains the trick. You know that little non-obvious thing that shows exactly how things are done. Then it’s easy! For example, have you ever wonder how Little Big Planet has very stable physics collisions, with no tunneling and no jitter? It must be really complicated right?




  33. Thanks a lot for your efforts, I like your writing style and how you can make readers to understand complicated things easily.
    I am doing some business apps for living, it is so boooring; so I am experimenting with various game programming related things to have fun and keep my brain in a good shape. Your articles really help keeping the coding fun and creative, and the best thing is that after reading each of your articles I can say – “oh my God, now I know how that complicated X stuff works and how to use it!”

    Thanks again.

  34. Pingback: Server side question.

  35. Pingback: Building a Network Library for a Video Game: Part 1 « Joeh's Blog

  36. Pingback: Cross Platform and Multiplayer Programming

  37. Count me in among the “you should write a book” crowd. I’d race to buy it. The sort of information you lay out in your articles is really hard to find all-in-one-place. I learned more about the networking aspects of game programming from reading your article series than I have from months of on and off google searching. You have a real talent for presenting the info at a good pace, not too dumbed-down, but also not too overly detailed. PLEASE publish a book someday. You’d be doing the world a big favor. Also, this sort of info is good for sitting down on the couch and reading through, rather than loading into the web browser (though that’s alright too). Dead trees still have their uses.

    Keep up the fantastic work.

    • Thank you very much. I think my strategy would be to just keep writing articles on this site. Eventually, I’ll have critical mass to assemble these into a book. I’d rather not sit down and decide “today I’m writing a book!”. But it’ll probably happen eventually. cheers

      • Well, you could do it in a “Gems” sort of book. Make it a collection of useful articles that would make good reference material.

    • It would need to be adapted to work with a client/server architecture but sure. You could just run the physics purely on the clients then have the server validate the physics and check it is within some tolerance. The bottleneck would of course be CPU cost on the server. Just FYI this is the hard thing I don’t believe there is any way around it =)

      • I’m in need of a distributed physics engine for MMO. A solution to distribute a bunch of cubes like in your demo, but server side.

        This is for MMO, therefore users have to be able to connect to the system, see and act is the virtual world…

        Do you think it’s even possible ?

  38. Hi Glenn,

    Thanks so much for your articles :p
    I’ve read this one ( and I wonder if you can tell us more about server side distributed physics, do you think it could be interesting for MMO Game ?
    How to distribute (on more than one servers) and compute the physics of a huge stacks of boxes for MMO game user ? Specialy MMOFPS game user, in fact :)


  39. I love your articles Glenn you are very knowledgeable and I like the way you researched the history of network gaming and brought the reader from past to present.

    Please keep writing!

    When are you going to put a book together?

    I am serious! :)


  40. hi a m an aspirant of game programming
    i m presently pursuing a graduation in computer science
    and preparing for SAT and GATE
    i need further consultancy in this field
    i want to know that in which subject or sub field of game programming or development
    i will do more study that is
    will i study —

    i want to know which subject will i study hardest and most deeply
    so that i will get more advantage in terms of experience , money , marketing and easiness
    help me

  41. Hey guys, some more articles have been added.

    For the immediate future I plan to expand the “what every programmer needs to know about game networking” series then create a new series about networked physics to support my GDC2009 physics tutorial talk

    After GDC I hope to return to the lower level networking articles, eg. reading/writing packets, sending events, synchronizing state etc…

    cheers all

  42. Brilliant, your articles are truly great. I just finished a unit about network programming at Uni. and it wasn’t nearly informative as your articles. Though more broad but beside the point. I wish I had read this article before the socket assignment.

  43. Any update on the articles?

    I’ve been wanting to try setting up an engine using event sourcing to get the state of an entity. But I’m not sure if there is too much overhead on calculating the state based on past events.

    • pretty busy working on my montreal talk coming up in a month. i hope to write the article on packet serialization shortly, also the slides from the talk should give you quite a bit of information – they will cover what you are interested in, basics of state based synchronization


  44. Very interesting and valuable read. Do you have plans to finish the tutorials listed after ‘Reliability and Flow Control’ ? I would very much enjoy reading them. :)

    Thank you for the work you’ve put in so far, it’s brilliant.

  45. Pingback: Cultus: Nätverksprogrammering

  46. Is “Real World Networking” gonna happen anytime soon?

    The stuff that I have read is really great! But, I really need to know how to actually connect clients through firewalls and NATs in the real world.

    I’d make a donation for that info….

    • Let me save you from waiting!

      My recommendation in that article will be either A) use the XBox-Live, or PSN APIs for consoles (which handle NAT punch-through for you) or B) Use a middleware solution for the NAT punch-through on PCs.

      You just don’t want to be writing this code yourself. It is too error-prone. Not even the pros roll their own here. Too many combinations of routers and weird behavior. Get somebody else to do it for you!

      ps. No donation required for this info :)

  47. Pingback: Программирование многопользовательских игр « Валерий Степанов

  48. Heya, I have recently taken a tumble down the nasty physics networking rabbit-hole. Your articles have been a great help with making sense of it all :)

    I was wondering what your thoughts were on
    . networking ragdoll physics (assuming [at a minumum] ragdoll root positions are important for gameplay)
    . networking physics joints (in general)

    Thanks for all the great articles

  49. Do you have any information on the hardware side of things? Such as good server hosting plans, installing your server app with that hosting, etc…

  50. Thank you for these articles. I have to fiddle with networking basics right now and these articles where the most helpful i’ve found. I hope to see more in near future.

  51. Good articles! Though I’m really familiar with basic networking concepts, your articles are very well written and informative.

    I am very much looking forward to your more indepth articles, especially on a node mesh and network synch.

    ~ Scott

  52. ok well most of what i found i had to work out myself, but there are some good resources out there, check out the networking forum FAQ on thats a pretty good collection of articles


  53. Hey thanks for letting us know. I have a question, what would you recommend to someone wanting to get up to speed in networking for games ?. I mean there’s enough info about the basics of networking but some of the info that you show here (at least have listed) is not easy to find in the web and you must have gathered all this from somewhere.

    Btw do you know how to build networking systems for massive multiplayer games ? I’m not talking about super complex tech, but good enough to have, say 500 people in a single server. If you do then I’m sure millions of ppl would like to know how everything works and I would hate to have to stalk you day and night until you write such articles.

    Seriously if you ever finish all the articles you listed here, a few extra on network architecture for mmos wouldn’t hurt.

  54. A very interesting set of articles: the things you handle are difficult, but you managed to grab these things and make them readable. The new article is really good and I recommend everyone, who wants to know something about networking, reading that one. It’s easy to grab, but a powerfull concept.
    Glenn, astonishing!

  55. Pingback: GameDevMike : Networking for Game Programmers

  56. Great series already !

    Much Information I never found anywhere else.
    (ie: tcp influence on udp when using both)

    I’m sure next series will answer much other question I have (netgame loop, server + client on same host, network queue management with priorities, threading, compression benefits or not, …)

    Here’s VS2005 working solution/proj and all (had to fix some compiler quirks, macro missing parenthesis, variable array allocation on stack, int to bool didn’t work in initialize connect, all working now.)

    You could setup a repository (svn +° wiki) with all you code so that patches and all becomes easier… meaning old articles code would also benefits from patches/updates.

    Again, thanks for all the work !

Leave a Reply

Your email address will not be published. Required fields are marked *