Easily create stunning presentations
Takes a few minutes to start

By Peter Bakhirev

Popular prezis

Networked Games on the iPhone

Presentation for Voices That Matter - iPhone 2009 dev conference

Turn-based
Real-time
Online
Local
Turn-based
Real-time
Online
Local
NetServices
+
TCP sockets
Use CFNetwork, or BSD sockets
Can be cross-platform
iPhone OS 2.0 and up
NetServices
+
UDP sockets
GameKit
NetServices
+
3rd party framework
Limited to iPhone OS-based devices
iPhone OS 3.0 and up (Bluetooth)
iPhone OS 3.1 and up (Wi-Fi)
Use CFNetwork, or BSD sockets
Can be cross-platform
iPhone OS 2.0 and up
Need custom "reliable" data delivery algorithm
Most likely iPhone OS 2.0 and up
Most likely cross-platform

NetServices
+
UDP sockets
GameKit
NetServices
+
3rd party framework
Limited to iPhone OS-based devices
iPhone OS 3.0 and up (Bluetooth)
iPhone OS 3.1 and up (Wi-Fi)
Use CFNetwork, or BSD sockets
Can be cross-platform
iPhone OS 2.0 and up
Need custom "reliable" data delivery algorithm
Most likely iPhone OS 2.0 and up
Most likely cross-platform

TCP sockets
Need central server
Use CFNetwork, or BSD sockets
Most likely cross-platform
iPhone OS 2.0 and up
UDP sockets
3rd party framework
Need central server
Use CFNetwork, or BSD sockets
Can be cross-platform
iPhone OS 2.0 and up
Need custom "reliable" data delivery algorithm
Need central server
Most likely iPhone OS 2.0 and up
Most likely cross-platform

UDP sockets
3rd party framework
Need central server
Use CFNetwork, or BSD sockets
Can be cross-platform
iPhone OS 2.0 and up
Need custom "reliable" data delivery algorithm
Need central server
Most likely iPhone OS 2.0 and up
Most likely cross-platform

6. Choosing the right framework
1. Turn-based vs Real-time games
4. Networking frameworks
3. TCP vs UDP
UDP
TCP
Stream of bytes
Guaranteed delivery
Based on connections
Slower due to acks and retransmissions
Individual packets
No guarantees 
No connections
Faster and simpler
"Transmission Control Protocol"
"User Datagram Protocol"
BSD sockets
CFNetwork
NetServices
GameKit
Flickr credit: Hamed Saber
Turn-based
Real-time
Take turns making moves (card games, board games)
Submit moves within a particular time frame (trivia)
Moves are made and propagated in real time
Nobody waits for anybody else
iPhone SDK
3rd party
CocoaAsyncSocket
http://code.google.com/p/cocoaasyncsocket/
enet
http://enet.bespin.org/
5. Multiplayer game needs
Maintain connectivity
Find the playground
Exchange data
2. Local vs Online multiplayer
Wi-Fi
EDGE
3G
Online
Wi-Fi
Bluetooth
Local
Client-server
Peer-to-peer
Server
Makes majority of gameplay decisions
Accepts connections from clients
Accepts messages from clients
Broadcasts messages to clients
Client
Makes a small number of gameplay decisions
Connects to the server
Sends and receives messages via the server
Peer
Makes all gameplay decisions related to "local" player
Maintains connectivity with all other peers
Communicates directly with all other peers
Might use a server to do "peer discovery"
Hybrid
GameKit
When more than 2 peers:
Connectivity like client-server
Logic like peer-to-peer
Local
Advertise your presence on the network
Look for other peers on the network
Online
Connect to server on the Internet
Use server to establish gaming session
1. Construct the message
2. Turn message into a network packet
3. Send packet out
4. Receive packet
5. Turn packet into message object
6. Process message
"marshal" or "serialize"
"unmarshal" or "deserialize"
= byte array
Networked Games on the iPhone
Presented by Peter Bakhirev, ByteClub.com
Thank you!  Questions?
Twitter: @byteclub
Email: peter@byteclub.com
1. Turn-based vs Real-time games

2. Local vs Online games

3. TCP/IP networking

4. Networking frameworks

5. Multiplayer game needs

6. Choosing the right framework

7. Code samples: serializing data

8. Advice and further reading
Table of contents
7. Code samples: Serializing messages
8. Advice and further reading
Hypothetical shooting game
with 2 network messages
Up to you to pick the delivery method
Construct message,
specify its type,
then turn it into a byte array
Same idea here...
1 byte header helps us
differentiate between messages
Your custom game logic here
Message serialization:
More performance, less flexibility
Represent each message as a 'struct'
Directly copy memory from struct into a byte array (NSData in this case)
Message serialization:
Less performance, more flexibility
Represent each message as an NSDictionary
Use NSKeyedArchiver to turn messages into byte arrays
VS
Use GameKit, unless you need cross-platform support.
Use stable 3rd party networking frameworks to save time and frustration.
Don't mix TCP and UDP. Don't use TCP for real-time games.
SSS: Stability, scalability and security - very important considerations for online multiplayer games.
Automate testing as much as possible. Multiplayer games have tricky bugs (especially online ones).
EDGE and 3G are slow! Don't underestimate how slow cell data network can be. It's hard to make an online real-time game work well via CDN.
Learn from Quake and Half-Life. If you do decide to create a real-time game, don't re-invent the wheel.
Google: "quake 3 network architecture"
Google: "latency compensation methods"
Forums and tutorials
Google: "Multiplayer and Network Programming"
  • Created by Peter Bakhirev
  • Networked Games on the iPhone
  • Presentation for Voices That Matter - iPhone 2009 dev conference
  • Share this prezi
  • Email
  • Twitter
  • Facebook
  • Report Abuse
  • Embed this prezi
  • Copy the code below
  • Copy to clipboard