SlideShare a Scribd company logo
1 of 95
Download to read offline
Game network
programming
PotHix (Willian Molinari)
Diego Souza (marciano)
Why?
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)
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
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

Similar to Game network programming

Running a Lean Startup with AWS - Spreaker Case Study
Running a Lean Startup with AWS - Spreaker Case StudyRunning a Lean Startup with AWS - Spreaker Case Study
Running a Lean Startup with AWS - Spreaker Case Study
Marco Pracucci
 
The Kumofs Project and MessagePack-RPC
The Kumofs Project and MessagePack-RPCThe Kumofs Project and MessagePack-RPC
The Kumofs Project and MessagePack-RPC
Sadayuki Furuhashi
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher
 
支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒
Toki Kanno
 

Similar to Game network programming (20)

L3DSR - Overcoming Layer 2 Limitations of Direct Server Return Load Balancing
L3DSR - Overcoming Layer 2 Limitations of Direct Server Return Load BalancingL3DSR - Overcoming Layer 2 Limitations of Direct Server Return Load Balancing
L3DSR - Overcoming Layer 2 Limitations of Direct Server Return Load Balancing
 
Introduction to Game Network Programming
Introduction to Game Network ProgrammingIntroduction to Game Network Programming
Introduction to Game Network Programming
 
사이드 프로젝트 빠르게 시작하기 by 제이제이
사이드 프로젝트 빠르게 시작하기 by 제이제이사이드 프로젝트 빠르게 시작하기 by 제이제이
사이드 프로젝트 빠르게 시작하기 by 제이제이
 
Using Python3 to Build a Cloud Computing Service for my Superboard II
Using Python3 to Build a Cloud Computing Service for my Superboard IIUsing Python3 to Build a Cloud Computing Service for my Superboard II
Using Python3 to Build a Cloud Computing Service for my Superboard II
 
Bigdata roundtable-storm
Bigdata roundtable-stormBigdata roundtable-storm
Bigdata roundtable-storm
 
Log
LogLog
Log
 
Lab 4 marking
Lab 4 markingLab 4 marking
Lab 4 marking
 
Harlan Beverly Lag The Barrier to innovation gdc austin 2009
Harlan Beverly Lag The Barrier to innovation gdc austin 2009Harlan Beverly Lag The Barrier to innovation gdc austin 2009
Harlan Beverly Lag The Barrier to innovation gdc austin 2009
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war story
 
Creating social games for millions of users
Creating social games for millions of usersCreating social games for millions of users
Creating social games for millions of users
 
Running a Lean Startup with AWS - Spreaker Case Study
Running a Lean Startup with AWS - Spreaker Case StudyRunning a Lean Startup with AWS - Spreaker Case Study
Running a Lean Startup with AWS - Spreaker Case Study
 
The Kumofs Project and MessagePack-RPC
The Kumofs Project and MessagePack-RPCThe Kumofs Project and MessagePack-RPC
The Kumofs Project and MessagePack-RPC
 
Image compression
Image compressionImage compression
Image compression
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using java
 
RTP
RTPRTP
RTP
 
支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒支撐英雄聯盟戰績網的那條巨蟒
支撐英雄聯盟戰績網的那條巨蟒
 
Lets Play Together
Lets Play TogetherLets Play Together
Lets Play Together
 
another day, another billion packets
another day, another billion packetsanother day, another billion packets
another day, another billion packets
 
Transaction preview of Apache Pulsar
Transaction preview of Apache PulsarTransaction preview of Apache Pulsar
Transaction preview of Apache Pulsar
 

More from Willian Molinari

Abertura do ruby_rails_no_mundo_real_guru_sp
Abertura do ruby_rails_no_mundo_real_guru_spAbertura do ruby_rails_no_mundo_real_guru_sp
Abertura do ruby_rails_no_mundo_real_guru_sp
Willian Molinari
 

More from Willian Molinari (16)

Desconstruindo a web
Desconstruindo a webDesconstruindo a web
Desconstruindo a web
 
Mesos
MesosMesos
Mesos
 
As escolhas do desenvolvedor
As escolhas do desenvolvedorAs escolhas do desenvolvedor
As escolhas do desenvolvedor
 
Desenvolvimento de jogos com HTML5 e javascript
Desenvolvimento de jogos com HTML5 e javascriptDesenvolvimento de jogos com HTML5 e javascript
Desenvolvimento de jogos com HTML5 e javascript
 
Javascript and browser games
Javascript and browser gamesJavascript and browser games
Javascript and browser games
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
 
Html5, gamedev e o skeleton jigsaw
Html5, gamedev e o skeleton jigsawHtml5, gamedev e o skeleton jigsaw
Html5, gamedev e o skeleton jigsaw
 
Ruby e xmpp
Ruby e xmppRuby e xmpp
Ruby e xmpp
 
Locasberos
LocasberosLocasberos
Locasberos
 
Simplestack
SimplestackSimplestack
Simplestack
 
Implementações paralelas
Implementações paralelasImplementações paralelas
Implementações paralelas
 
TDC2011 - Desenvolvimento de jogos com Javascript e HTML5
TDC2011 - Desenvolvimento de jogos com Javascript e HTML5TDC2011 - Desenvolvimento de jogos com Javascript e HTML5
TDC2011 - Desenvolvimento de jogos com Javascript e HTML5
 
FLISOL SJC - Desenvolvimento de jogos com javascrit e HTML5
FLISOL SJC - Desenvolvimento de jogos com javascrit e HTML5FLISOL SJC - Desenvolvimento de jogos com javascrit e HTML5
FLISOL SJC - Desenvolvimento de jogos com javascrit e HTML5
 
Abertura do ruby_rails_no_mundo_real_guru_sp
Abertura do ruby_rails_no_mundo_real_guru_spAbertura do ruby_rails_no_mundo_real_guru_sp
Abertura do ruby_rails_no_mundo_real_guru_sp
 
Vim
VimVim
Vim
 
What is and how does work RubyLearning.org
What is and how does work RubyLearning.orgWhat is and how does work RubyLearning.org
What is and how does work RubyLearning.org
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Game network programming