Game Networking CS381 Sushil J. Louis Dept. of Computer Science and Engineering University of Nevada, Reno From and much thanks to

Slides:



Advertisements
Similar presentations
Introduction 1 Lecture 13 Transport Layer (Transmission Control Protocol) slides are modified from J. Kurose & K. Ross University of Nevada – Reno Computer.
Advertisements

Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
Intermediate TCP/IP TCP Operation.
Gameplay Networking Jacob Steinfort. Importance of Multiplayer Games If gamers had to choose either a single-player game or a multiplayer game, most people.
IS333, Ch. 26: TCP Victor Norman Calvin College 1.
Chapter 7 Intro to Routing & Switching.  Upon completion of this chapter, you should be able to:  Explain the need for the transport layer.  Identify.
Network synchronization of Online Games Li, Zetan.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
1 Java Networking – Part I CS , Spring 2008/9.
CSCE 515: Computer Network Programming TCP Details Wenyuan Xu Department of Computer Science and Engineering.
WXES2106 Network Technology Semester /2005 Chapter 8 Intermediate TCP CCNA2: Module 10.
3-1 Transport services and protocols r provide logical communication between app processes running on different hosts r transport protocols run in end.
What Is TCP/IP? The large collection of networking protocols and services called TCP/IP denotes far more than the combination of the two key protocols.
Process-to-Process Delivery:
TRANSPORT LAYER T.Najah Al-Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System NET331.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
6.1. Transport Control Protocol (TCP) It is the most widely used transport protocol in the world. Provides reliable end to end connection between two hosts.
1 7-Oct-15 OSI transport layer CCNA Exploration Semester 1 Chapter 4.
Discussion 2 Sockets Programming Applets TCP UDP HTTP Delay Estimation
Application Layer 2-1 ESERCITAZIONE SOCKET PROGRAMMING.
CS332, Ch. 26: TCP Victor Norman Calvin College 1.
TCP/IP TCP/IP LAYERED PROTOCOL TCP/IP'S APPLICATION LAYER TRANSPORT LAYER NETWORK LAYER NETWORK ACCESS LAYER (DATA LINK LAYER)
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.

Transport Layer 3-1 Chapter 3 Transport Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012 Part.
Introduction to Network Programming with Sockets Network Programming Kansas State University at Salina.
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Principles of reliable data transfer 0.
Transport Layer Moving Segments. Transport Layer Protocols Provide a logical communication link between processes running on different hosts as if directly.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
1 Networking Chapter Distributed Capabilities Communications architectures –Software that supports a group of networked computers Network operating.
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012.
Chapter 15 – Part 2 Networks The Internal Operating System The Architecture of Computer Hardware and Systems Software: An Information Technology Approach.
Transport Layer COM211 Communications and Networks CDA College Theodoros Christophides
The InetAddress Class A class for storing and managing internet addresses (both as IP numbers and as names). The are no constructors but “class factory”
Networking Basics CCNA 1 Chapter 11.
Lecture 4 Overview. Ethernet Data Link Layer protocol Ethernet (IEEE 802.3) is widely used Supported by a variety of physical layer implementations Multi-access.
Institute of Technology Sligo - Dept of Computing Chapter 12 The Transport Layer.
TCP continued. Discussion – TCP Throughput TCP will most likely generate the saw tooth type of traffic. – A rough estimate is that the congestion window.
Networks, Part 2 March 7, Networks End to End Layer  Build upon unreliable Network Layer  As needed, compensate for latency, ordering, data.
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Principles of reliable data transfer 0.
4343 X2 – The Transport Layer Tanenbaum Ch.6.
INTRO TO NETWORKING. OVERVIEW Transmitting data Across a physical media Ethernet Wi-fi Bluetooth Etc. Cross-platform (usually) Challenges Varying network.
UDP : User Datagram Protocol 백 일 우
1 Kyung Hee University Chapter 11 User Datagram Protocol.
Data Communications and Networks Chapter 6 – IP, UDP and TCP ICT-BVF8.1- Data Communications and Network Trainer: Dr. Abbes Sebihi.
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
TCP/IP1 Address Resolution Protocol Internet uses IP address to recognize a computer. But IP address needs to be translated to physical address (NIC).
Process-to-Process Delivery:
© 2006 Cisco Systems, Inc. All rights reserved.Cisco Public 1 OSI transport layer CCNA Exploration Semester 1 – Chapter 4.
Chapter 9 The Transport Layer The Internet Protocol has three main protocols that run on top of IP: two are for data, one for control.
Game Networking CS381 Spring Internet ● An information superhighway ● A collection of pipes ● Arpanet – Robust communication in the face of infrastructure.
Networking Project. Game Networking Game Networking Topology Star (client/server) Topology – All devices are connected to a central hub (server) – Nodes.
Chapter 11 User Datagram Protocol
The Transport Layer Implementation Services Functions Protocols
Fast Retransmit For sliding windows flow control we waited for a timer to expire before beginning retransmission of a packet TCP uses an additional mechanism.
Unity Networking.
CMPT 371 Data Communications and Networking
Magda El Zarki Professor, ICS UC, Irvine
Subject Name: Computer Communication Networks Subject Code: 10EC71
Packet Sniffing.
Topic 5: Communication and the Internet
Process-to-Process Delivery:
CPEG514 Advanced Computer Networkst
Process-to-Process Delivery: UDP, TCP
Data Communication and Computer Networks
Computer Networks Protocols
Chapter 3 Transport Layer
Transport Layer 9/22/2019.
Exceptions and networking
Presentation transcript:

Game Networking CS381 Sushil J. Louis Dept. of Computer Science and Engineering University of Nevada, Reno From and much thanks to

Internet  Internet connectivity is usually over TCP/IP sockets  TCP Sockets look like this M1M2 write read write  Reading from a socket is like reading from a file  Writing to a socket is like writing to a file  So  How M1 and M2 are not directly connected by a wire  Messages (or packets) are routed over the internet using the Internet Protocol (IP)

TCP / IP Sockets  IP is Internet Protocol  M1will pass packets to the next computer (router) in the direction of M2  No guarantee that packet will reach M2  TCP is Transmission Control Protocol  Implementation is complicated! But TCP sockets include this implementation  Sets up a connection between M1 and M2 to make reading and writing over sockets as simple as reading / writing files  Built on top of IP to guarantee error free, complete, in- order delivery

UDP Sockets  UDP is User Datagram Protocol  Very thin layer on top of IP  Sender:  Sends packet over IP to destination address (M2) and port  NO delivery guarantee  Receiver  Listens on port on M2 and when a packet arrives from ANY machine, you get the address of sender, the size, and you can read the message  UDP is unreliable  1-5% of packets get lost usually – sometimes 100%  No ordering: M1 sends1,2,3,4,5. M2 gets 3,1,2,5,4  If you get packet, you get packet error free

TCP/IP Python Socket Code # TCP server example import socket server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(("", 5000)) server_socket.listen(5) print "TCPServer Waiting for client on port 5000" while 1: client_socket, address = server_socket.accept() print "I got a connection from ", address while 1: data = raw_input ( "SEND( TYPE q or Q to Quit):" ) if (data == 'Q' or data == 'q'): client_socket.send (data) client_socket.close() break; else: client_socket.send(data) data = client_socket.recv(512) if ( data == 'q' or data == 'Q'): client_socket.close() break; else: print "RECIEVED:", data

Code # TCP client example import socket client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect(("localhost", 5000)) while 1: data = client_socket.recv(512) if ( data == 'q' or data == 'Q'): client_socket.close() break; else: print "RECIEVED:", data data = raw_input ( "SEND( TYPE q or Q to Quit):" ) if (data <> 'Q' and data <> 'q'): client_socket.send(data) else: client_socket.send(data) client_socket.close() break;

UDP/IP Python Socket Code # UDP server example import socket server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) server_socket.bind(("", 5000)) print"UDPServer Waiting for client on port 5000" while 1: data, address = server_socket.recvfrom(256) print "( ",address[0], " ", address[1], " ) said : ", data

UDP/IP Python Socket Code # UDP client example import socket client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) while 1: data = raw_input("Type something(q or Q to exit): ") if (data <> 'q' and data <> 'Q'): client_socket.sendto(data, ("localhost",5000)) else: break client_socket.close()

Networking Games UDP vs TCP  Connection based  Guaranteed reliable and ordered  Automatically breaks up data into packets for you  Makes sure it doesn’t send data too fast for the connection to handle (flow control)  Easy  Like Reading/Writing from/to a file  No concept of connection – you have to code this  No guarantee of reliability or ordering of packets. Duplicate and Lost packets possible  You have to packetize  You have to handle flow control  If packet loss, you have to detect and get the packet resent or otherwise handle it We should obviosly use TCP over IP right?

Real-time networked games use UDP!  Games need latest data, fast – old game state is useless  TCP packetizes and queues up small packets to send  Queuing can cause delays  TCP_NODELAY option gets rid of this problem  TCP reliability implementation can cause delays  What happens when a packet is lost?  What happens when a packet arrives out of order?  Detect loss and ask for sender to resend lost packet  Even if newer data arrives, M2 has to wait till old data packet gets resent  If the old data packet also gets lost?.... Very bad.

TCP bad – UDP good  M1 sends data packets [d1, d2, d3, d4, ….] to M2  M2 acknowledges each packet sent by sending an ack packet to M1 [a1, a2, a3, a4]  Now suppose a data packet, d2, gets lost,  Assume 70 ms to get from M1 to M2  M1 send d2, waits for 140 ms to get a2 from M2  d2 got lost!  M1 sends d2 again 140 ms after it first sent it and it takes 70 ms to M2 to get d2  M2 gets d2 210 ms after it was first sent in the BEST case  Suppose d2 again gets lost, ½ second delays possible!  RT games cannot deal with this kind of delay – think flying bullets  What happened a second ago does not matter  So games use UDP – check out OpenEcslent’s Network Manager and Network Aspect.

game-programmers/udp-vs-tcp/  Consider a very simple example of a multiplayer game, some sort of action game like a shooter. You want to network this in a very simple way. Every frame you send the input from the client to the server (eg. keypresses, mouse input controller input), and each frame the server processes the input from each player, updates the simulation, then sends the current position of game objects back to the client for rendering.  So in our simple multiplayer game, whenever a packet is lost, everything has to stop and wait for that packet to be resent. On the client game objects stop receiving updates so they appear to be standing still, and on the server input stops getting through from the client, so the players cannot move or shoot. When the resent packet finally arrives, you receive this stale, out of date information that you don’t even care about! Plus, there are packets backed up in queue waiting for the resend which arrive at same time, so you have to process all of these packets in one frame. Everything is clumped up!

Use both TCP and UDP?  NO because TCP affects UDP packet loss. TCP causes UDP packet loss

Peer to Peer Lockstep  No client, no server  Fully connected mesh topology  Easiest  First developed for RTS  Turns and commands  Common initial state (starting in a game lobby)  Beginning of each TURN  Send all commands to all machines  All machines run commands  End Turn

Peer to Peer lockstep  Simple, elegant.  Non-linearity  Ensuring complete determinism is hard. Slight differences amplify with time  Latency  All commands must be received before simulating that turn. Latency = max latency over all players!  Command and Conquer, Age of Empire, Starcraft  Best over LANs But…

Client/Server  Lockstep not good for action games like DOOM over internet.  Each player is now a client and they all communicate with a server.  Server ran the game simulation, dumb clients interpolated between states received from the server  All input goes from clients to server  Keypresses, mouse movement, presses  Server simulates, changes entity states  Client gets new entity states, interpolates between old and new states  Players could come and go in the middle of the game. Quality of connection depends on client server connection

Client server problems  Latency is still the big problem

Client-side prediction  Client-side prediction  Latency compensation  Interpolation  John Carmack on QuakeWorld  I am now allowing the client to guess at the results of the users movement until the authoritative response from the server comes through. This is a biiiig architectural change. The client now needs to know about solidity of objects, friction, gravity, etc. I am sad to see the elegant client-as-terminal setup go away, but I am practical above idealistic.

Client-side prediction  All machines are the same and run the same code  no dumb clients  One machine is still the authority  server  So  Client simulates the movement of your entity locally and immediately in response to your input  No latency issue. Immediate movement  How do I synchronize with all the other players?  Communicate with server and correct your movement in response to server state messages

Client-side prediction  But server state is past-state!  If it takes 200 ms for round trip message between client and server, then server correction for the player character position will be 200 ms in the past,.relative to now Client Server Move Moved 200 ms Moved 100 ms

Client-side prediction soln  Keep a buffer of past local state (and input) for each entity  When client gets correction from server  Discard state older than server state  Simulate from server state to now  This is your (client entity) new predicted position using latest info from server  Look at the difference in position  Between the predicted position and your current position  pDiff  Note network latency  Keep simulating forward from current position, but interpolate to eliminate pDiff within latency amount of time  By the time you next get a correction from server, your predicted position should be your current position!

How do you network games? OpenEcslent Networking: Server Running game Client Running game Commands Server game state

How do you network games? OpenEcslent Networking: Game Engine Gfx Mgr Entity Mgr Network Mgr Network Sender Thread Network Receiver Thread tick Thread run loops

C1 state 381 engine networking  All machines run the game  Whenever either user gives a command, the network subsystem sends the command and arguments to the server  Server BROADCASTS game state to all clients  Time stamp  pos, vel, orientation,  desiredSpeed, desiredHeading  Client syncs game state with Server’s state Server C2C7 dh, ds

Client Sync  Network thread  Get data packet  Put in queue  Get LATEST data from queue (Game Thread)  Switch (type of data) {  Case (Game state): (this is in netAspect.py)  Update latency, t  For each entity, e, in data packet  Get pos, ori of entity, from t seconds ago  Predict where server entity will be now, if it was at pos, t seconds ago (physics)  Predict server entity’s orientation, if it was at ori, t seconds ago (physics)  Look at the difference in current and predicted pos and ori. Using this difference  Interpolate over t seconds to move entity from current pos to predicted pos  Interpolate over t seconds to move entity from current ori to predicted ori

UDP packets  Max size is bytes  Open Ecslent packet design  Every packet has  Packet type: state, command, info, info request, …(2 bytes)  For how many ents: (say 4 bytes)  Game state packet (openEcslent)  Must be big enough to hold state for all entities in simulation  px, py, pz, vx, vy, vz, speed, yaw, dh, ds (10 * 4 = 40 bytes)  – 6 = 65530/40 = 1638 ents supported. Packet header Packet data

OpenEcslent Protocol  Server has two threads  One thread broadcasts state every 100 ms  Second thread handles client requests  Request for info about new entity  User command that changes entity’s dh, ds  …  Client has two threads  One thread sends commands  Other thread handles server messages  If games state message type  If known entity: sync  If unknown entity:  Ask for entity info  If entity info message type:  Create entity Originally designed by Michael Oberberger