4. Network Communication - a-roy/pacman-mp GitHub Wiki

Network Technology

Data will be transmitted over the UDP protocol because it is faster than TCP and has defined packet boundaries. Information should be sent in multiple copies in order to maximize the likelihood that information is properly received. During gameplay, we can easily send inputs for 10 or more frames at a time because this data is very small.

Network Architecture

The network functionality of this application will be based on a client-server architecture. The server's main responsibilities are to ensure that clients are connected, collect inputs, broadcast inputs, and keep clients synchronized. Each client's responsibilities include sending inputs to the server, collecting inputs from the server, and running game logic.

Packet Structure

  • Byte 0: Application signature
  • Byte 1: Message type
  • Byte 2+: Additional data

Types of Messages

Server to Client

  • Connection confirmation
  • Lobby ping
  • Game start notification
  • Player inputs
  • Synchronization command
  • Game end notification
  • Disconnection notice

Client to Server

  • Connection request
  • Lobby ping
  • Player inputs
  • Game end notification
  • Disconnection notice