250 likes | 274 Views
Network and Multiplayer. Multiplayer Modes: Restricting the Domain. Real-Time not Turn-Based Sure its more difficult to implement Yes its more latency sensitive Considering only internet multi-user
E N D
Multiplayer Modes:Restricting the Domain Real-Time not Turn-Based Sure its more difficult to implement Yes its more latency sensitive Considering only internet multi-user Internet uses shared pipes and has extremely highly variable latency, bandwidth, and reliability Shared keybord/screen, or bluetooth or USB hookups are out of our scope
Protocols:Protocol Design Packet Length Acknowledgment Methodology Error Checking / Correcting Compression Encryption
Protocols:Packets Packets Header = Protocol Manifest. Overhead. Data Payload Gotchas (No) “normal” Pointers or References Large Data, Variable Size Data Beware Classes/Objects (serialize? But carefully) Binary data limits portability: Word Size, Byte Alignment, Endian Order Unicode vs. ASCII Strings
Protocols: Request for Comments RFC web site http://www.rfc-editor.org/ Protocol Specifications Definitive Resource Public Criticism Future Protocols
Protocol Stack:Physical Layer Bandwidth Width of data pipe Measured in bps = bits per second Latency Travel time from point A to B Measured in Milliseconds (<50 local, 150 typical, 1500+ common) Table: Max Bandwidth Specifications
Protocol Stack:Network Layer Packet Routing Hops (check out traceroute) Routers, Hubs, Switches Packet fragments and reassembly as needed Internet Protocol (IP) Contains Source & Destination IP Address In practice, public vs. private internet IP# only gets to your firewall/router NAT is ubiquitous, making peer-to-peer and servers more difficult to write
Protocol Stack:Network Layer: IP Address Normal == Unicast Send to one particular IP# Static vs. DHCP Multicast Requires multicast capable router Broadcast Local Directed Loop Back Send to self AddrAny 0 = address before receiving an address
Protocol Stack:Network Layer: DNS Domain Name Service Converts text name to IP address Must contact one or more DNS servers to resolve Frequently attacked Local cache resolution possible Game Tips Store local game cache to use when DNS “out of order”. <-- DNS often out of order When not dead, DNS resolution often very slow, use cache for same day resolution.
Protocol Stack:Transport Layer Manage data delivery between endpoints Error recovery - retransmit Data “flow” - reorder TCP and UDP sit atop IP Contains Source and Destination Port Port + IP = Net Address Port Range = 0-64k Well known Ports 0-1k
Protocol Stack:Transport Layer: TCP Guaranteed Correct In Order Delivery Acknowledgement system Ack, Nack, Auto Resend Checksum Out of Band Connection Required-kinda slow to setup Packet Window Packet Coalescence Keep Alive Streamed Data A byte sequence. User must serialize data
Protocol Stack:Transport Layer: UDP Non Guaranteed Delivery No Acknowledgment system May arrive out of order Checksum Not Connected Source not verified Hop Count Limit = TTL (time to live) Required for Broadcasting Datagram Sent in packets exactly as user sends them
Protocol Stack:Session Layer Manages Connections between Apps Connect Terminate Data Exchange Socket API live at this layer Cross platform Cross language
Protocol Stack:Session Layer:TCP Sockets Based on File I/O File Descriptors Open/Close Read/Write Winsock Provides standard specification implementation plus more Extension to spec prefixed with “WSA” Requires call to WSAStartup() before use Cleanup with WSAShutdown()
Protocol Stack:Session Layer: Socket Design Modes Blocking – requires dedicated thread, single connection Non-Blocking Standard Models Standard “select” - multiple net connections, e.g. X11, VE server(s), peer(s) and DB server(s) if all serviced by same thread
Protocol Stack:Presentation Layer Options Prepare App Data for Transmission Compression Consider using “Pascal strings”. String Tables – JSON vs. XML, reduction to ints Float to Fixed Matrix to Quaternion Encryption Sizing, Endean Order Fixups If binary data is used cross platform or cross language Serialize Pointers --> transmit via deep copy or proxy Variable Length Arrays
Protocol Stack:Presentation Layer: Buffering Packet Coalescence – kernels handle limited # of packets/sec regardless whether big or small Induced Latency – applications see buffering as More latency Dead Data – some data is obsoleted before it even gets transmitted. Large Packets – well, within reason
Protocol Stack:Application Layer Handles Game Logic Update Models Input Reflection State Reflection Synchronization Dead Reckoning AI Assist Arbitration
Real-Time Communications:Connection Models Broadcast Mostly obsolete, except for player discovery on LANs Peer to Peer Good for 2 player games, beware NAT Client / Server Good for 2++ player games Dedicated lobby server great for player discovery
Real-Time Communications:Peer to Peer vs. Client/Server N = Number of players
Real-Time Communications:Asynchronous Environments Thread Priority Suspension Pooling Synchronization Critical Section & Mutex Communication Signal & Event Shared Memory pitfalls
Firewalls Packet Filter – implements include/exclude rules. Might just allow specific ports through Packet Shaping – prevent your Netflix from freezing my Emacs session. Proxies – an agent acting on another’s behalf
Firewalls: NAT Traversal Specifics configured on router Determining WAN IP Hole punching