SlideShare a Scribd company logo
Game network
programming
PotHix (Willian Molinari)
Diego Souza (marciano)
Why?
Game network programming
Skeleton Jigsaw: http://plaev.me/skeleton-jigsaw

              Shameless self promotion
To have fun, bro!
Agenda
■ Synchronous RTS
■ Peer to peer
■ Client / server
■ UDP
■ Quake strategy
■ TCP
■ Web and HTML5
Synchronous RTS
RTS's and Supreme commander
Peer to peer
Everything in sync
Two gameloops!
Latency
My life for the horde!
Player1   Player2   Player3


 tick 0ms



tick 100ms



tick 200ms



tick 300ms



tick 400ms
Player1   Player2   Player3


 tick 0ms



tick 100ms



tick 200ms



tick 300ms



tick 400ms
Player1   Player2   Player3


 tick 0ms



tick 100ms



tick 200ms



tick 300ms



tick 400ms
Player1   Player2   Player3


 tick 0ms



tick 100ms



tick 200ms



tick 300ms



tick 400ms
butterfly effect
So...
Player1   Player2   Player3


 tick 0ms



tick 100ms



tick 200ms



tick 300ms



tick 400ms
Player1        Player2   Player3


 tick 0ms



tick 100ms
                   UI OK!


tick 200ms



tick 300ms



tick 400ms
Desync
Age of empires
1500 archers with a 28.8 modem [1]
Client / Server
Authoritative server
Client   Server




                  pos (0,0)
Client   Server




                              pos (0,0)

pos (0,0)
Client   Server




                              pos (0,0)

pos (0,0)


move


pos (1,0)
Client   Server




                              pos (0,0)

pos (0,0)


move


pos (1,0)


                              pos (1,0)
Smartass
Client   Server




                  pos (0,0)
Client   Server




                              pos (0,0)

pos (0,0)
Client   Server




                                  pos (0,0)

pos (0,0)


move


pos (100,200)
Client   Server




                                      pos (0,0)

pos (0,0)


move


pos (100,200)


                                  pos (100,200)
Game network programming
Client   Server




                  pos (0,0)
Client   Server




                              pos (0,0)

pos (0,0)
Client   Server




                               pos (0,0)

pos (0,0)



move right


                               pos (1,0)
Client   Server




                               pos (0,0)

pos (0,0)



move right


                               pos (1,0)



 pos (1,0)
Victory!
Client side prediction
Client   Server




                  pos (0,0)
Client   Server




                              pos (0,0)

pos (0,0)
Client   Server




                               pos (0,0)

pos (0,0)



move right


                               pos (1,0)
Client   Server




                               pos (0,0)

pos (0,0)



move right


                               pos (1,0)



 pos (1,0)
Client   Server




                                  pos (0,0)

   pos (0,0)



   move right



Latency                           pos (1,0)



    pos (1,0)
Client   Server




                                           pos (0,0)

      pos (0,0)



       move right



Animation                                  pos (1,0)



        pos (1,0)




            Predicting
Client   Server




                                           pos (0,0)

      pos (0,0)



       move right



Animation                                  pos (1,0)



        pos (1,0)




            Predicting
Client   Server




                                      pos (0,0)

      pos (0,0)



       move right



Animation                             pos (2,0)



        pos (1,0)
Client   Server




                                      pos (0,0)

       pos (0,0)



       move right



Animation                             pos (2,0)



        pos (1,0)


Correction

        pos (2,0)
Quake
https://github.com/id-Software
UDP
datagrams, unreliable, unordered
rcv_buf >= snd_buf
All receive operations return only one packet
          watch out for MSG_TRUNC
auto ip_mtu_discover
 enabled by default
  EMSGSIZE signals packet too big
65k max theoretical packet
 limit (headers included)
    rfc defines the size header to 16bits
however, 1472 is likely the
max you may get, 576 to be
          sure
         MTU - headers
remember the TOS
throughput, reliability, lowdelay (etc.)
Quake world
https://github.com/id-Software/Quake
All credits to Fabien Sanglard: http://fabiensanglard.net/quakeSource/quakeSourceNetWork.php
        Code: https://github.com/id-Software/Quake/blob/master/QW/client/net_chan.c
Quake III arena
https://github.com/id-Software/Quake-III-Arena
Snapshots based
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
All credits to Fabien Sanglard: http://fabiensanglard.net/quake3/network.php
Open source code!
https://github.com/id-Software/Quake-III-Arena/blob/master/code/qcommon/msg.c
TCP
Streaming, reliable, connection oriented
TCP tuning
Long story short: use auto-tune
You probably just need to tune the maximum values
                   (system wide)
High-performance extensions
        refer to rfc1323
Bandwidth-delay product
data link's capacity (in bits per second) and its end-to-
                end delay (in seconds).
10Mbs x 1ms = 1.22 KB
10Mbs x 200ms = 244 KB
    rfc1323: huge buffers
CORK
don't send partial frames
NODELAY
disable nagle's algorithm
socket options
https://gist.github.com/4036204
benchmarking
Game network programming
Game network programming
BBG* and HTML5
  *Browser based games
The same thing...
     ...but not...
No TCP
   No UDP
No peer to peer
Chrome support!?
http://developer.chrome.com/apps/app_network.html
HTTP
Websockets
Mozilla multiplayer game: http://browserquest.mozilla.org
Blackberry
                                browser
           Chrome
                                             Opera
Mobile safari


                    Browsers
    IE
                                            Android browser
                     Firefox

  Opera mini
                                              Safari
Caniuse.com: websockets marketshare
Socket.io
Fallbacks all over the place
Bandwidth
We're back again
References
■ [1] Age of empires paper
■ Synchronous RTS engines
■ Client / server tricks
■ Quake code reviews
■ Improving bandwidth for websockets
■ Unreal networking architecture
■ http://tools.ietf.org/html/rfc1323
References
■ http://linux.die.net/man/7/udp
■ http://linux.die.net/man/7/ip
■ http://linux.die.net/man/7/socket
■ http://en.wikipedia.org/wiki/Nagle's_algorithm
■ http://en.wikipedia.org/wiki/Bandwidth-
  delay_product
References
■ http://tools.ietf.org/html/rfc1046
■ http://linux.die.net/man/7/tcp
Game over

More Related Content

KEY
Message queueing
KEY
Message Queueing - by an MQ noob
PDF
Toster - Understanding the Rails Web Model and Scalability Options
PDF
XS Boston 2008 Stub Domains
PDF
XS Japan 2008 Isolation Japanese
DOCX
Destination NAT.docx
KEY
Streams are Awesome - (Node.js) TimesOpen Sep 2012
PDF
Hudson以外の何か with 任意
Message queueing
Message Queueing - by an MQ noob
Toster - Understanding the Rails Web Model and Scalability Options
XS Boston 2008 Stub Domains
XS Japan 2008 Isolation Japanese
Destination NAT.docx
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Hudson以外の何か with 任意

Similar to Game network programming (20)

PDF
Akka for realtime multiplayer mobile games
PDF
Akka for realtime multiplayer mobile games
PPTX
Photon Session / Unite12 Conference
PDF
Jan Hloušek, Keen Software House
KEY
Networked physics 2011
KEY
GDC Networked Physics 2011
ZIP
GDC Networked Physics 2011
KEY
Networked Physics 2011
PPT
Multiplayer Games Chapter 6 Network Topologies.ppt
PPTX
Game Networking for Online games
PPT
Realtime html5 multiplayer_games_with_node_js
PDF
CS4344 09/10 Lecture 2: Consistency
PDF
CS4344 Lecture 3: Dead Reckoning and Local Perception Filter
PDF
You are not alone - Scaling multiplayer games
PDF
CS4344 09/10 Lecture 8: Hybrid Architecture
PPTX
Asynchronous Multiplayer on Mobile Network
PDF
Tech solutions and tricks in real time mobile multiplayer
PDF
Reliving the history of multiplayer games
PPTX
Collaborate nfs kyle_final
PDF
Scalability & Big Data challenges in real time multiplayer games
Akka for realtime multiplayer mobile games
Akka for realtime multiplayer mobile games
Photon Session / Unite12 Conference
Jan Hloušek, Keen Software House
Networked physics 2011
GDC Networked Physics 2011
GDC Networked Physics 2011
Networked Physics 2011
Multiplayer Games Chapter 6 Network Topologies.ppt
Game Networking for Online games
Realtime html5 multiplayer_games_with_node_js
CS4344 09/10 Lecture 2: Consistency
CS4344 Lecture 3: Dead Reckoning and Local Perception Filter
You are not alone - Scaling multiplayer games
CS4344 09/10 Lecture 8: Hybrid Architecture
Asynchronous Multiplayer on Mobile Network
Tech solutions and tricks in real time mobile multiplayer
Reliving the history of multiplayer games
Collaborate nfs kyle_final
Scalability & Big Data challenges in real time multiplayer games
Ad

More from Willian Molinari (16)

PDF
Desconstruindo a web
PDF
As escolhas do desenvolvedor
PDF
Desenvolvimento de jogos com HTML5 e javascript
PDF
Javascript and browser games
PDF
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
PDF
Html5, gamedev e o skeleton jigsaw
PDF
Ruby e xmpp
PDF
Locasberos
PDF
Simplestack
PDF
Implementações paralelas
PDF
TDC2011 - Desenvolvimento de jogos com Javascript e HTML5
PDF
FLISOL SJC - Desenvolvimento de jogos com javascrit e HTML5
PDF
Abertura do ruby_rails_no_mundo_real_guru_sp
PDF
What is and how does work RubyLearning.org
Desconstruindo a web
As escolhas do desenvolvedor
Desenvolvimento de jogos com HTML5 e javascript
Javascript and browser games
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
Html5, gamedev e o skeleton jigsaw
Ruby e xmpp
Locasberos
Simplestack
Implementações paralelas
TDC2011 - Desenvolvimento de jogos com Javascript e HTML5
FLISOL SJC - Desenvolvimento de jogos com javascrit e HTML5
Abertura do ruby_rails_no_mundo_real_guru_sp
What is and how does work RubyLearning.org
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Encapsulation theory and applications.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Machine learning based COVID-19 study performance prediction
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Encapsulation theory and applications.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Digital-Transformation-Roadmap-for-Companies.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Assigned Numbers - 2025 - Bluetooth® Document
Machine learning based COVID-19 study performance prediction
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
Reach Out and Touch Someone: Haptics and Empathic Computing
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
“AI and Expert System Decision Support & Business Intelligence Systems”
A comparative analysis of optical character recognition models for extracting...
Unlocking AI with Model Context Protocol (MCP)
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf

Game network programming