Networking,
Built In.

Three networking layers ship with the engine, from Python and C++: ENet for low-latency sessions over UDP, plain TCP and UDP datagrams, and Distributed Objects — networked classes declared once in a schema and replicated to the clients that are interested in them.

ENet Reliable UDP Distributed Objects DC Schema Files Zone Interest Smoothed Movement
ENet Docs Distributed Objects Docs

One Object, Several Views

A distributed object is created once and copied to every interested client; updates to it propagate to the copies. Each process holds the view of the object it needs — the client a proxy, the AI server the game logic.

Client
ClientRepository
Connects to the server, opens interest in zones, and holds the client-side copies — DistributedObject classes — of what it can see.
Server
ServerRepository
Routes messages between the clients and the AI processes and keeps track of which objects live in which zone.
Game Logic
AIRepository
Runs the authoritative side of each object — DistributedObjectAI classes — apart from the clients. Uber DOGs serve game-wide requests.

01

DC Schema Files

Networked classes, their fields and their remote methods are declared in a .dc file, with keywords for who may send a field and who receives it. Every process reads the same file, so it is the contract on the wire.

02

Zones & Interest

Objects live in zones, and a client receives only the objects in the zones it has opened interest in. Cartesian-grid objects place their children in grid cells for open worlds.

03

Smoothed Movement

DistributedSmoothNode broadcasts position and rotation and smooths them on the other clients, with optional prediction, and a time manager keeps the clocks in step.

04

Owner Views & Global Objects

An owner view gives the owning client its own interface to an object; Uber DOGs are game-wide objects with fixed ids for requests such as sign-in.

05

ENet Sessions

For a server and a handful of clients, ENet gives connections over UDP with per-packet reliable or unreliable delivery, several channels, fragmentation, throttling and packet-loss statistics.

06

Datagrams

Under both, the engine's Datagram classes and a connection manager for TCP and UDP — for when you want to design the protocol yourself.

Declare Once,
Implement Per Side

Declare the networked class in a DC file, then write the client and the AI class that implement it. Sending a field is a method call; receiving one calls the method of the same name.

  • ▪Python or C++ — the networking classes are available from both
  • ▪Typed fields — the DC file fixes each field's types and who may send it
  • ▪Server-side authority — airecv fields go to the AI, which decides and broadcasts
game.dc — schema
from direct.distributed import DistributedNode/AI

dclass DistributedAvatar : DistributedNode {
  setName(string name) required broadcast ram;
  setHp(uint16 hp) required broadcast ram;
  requestAttack(uint32 targetId) airecv clsend;
};
DistributedAvatarAI.py — server logic
from direct.distributed.DistributedNodeAI import DistributedNodeAI

class DistributedAvatarAI(DistributedNodeAI):
    hp = 100

    def requestAttack(self, targetId):
        target = self.air.doId2do.get(targetId)
        if target is None:
            return
        target.b_setHp(max(0, target.hp - 10))

    def setHp(self, hp):
        self.hp = hp

    def b_setHp(self, hp):
        self.setHp(hp)                        # here
        self.sendUpdate('setHp', [hp])   # and to every client

Run Your Own Servers

The server side is part of the engine: a server is a Python or C++ program you build and run like the game itself, on a single machine or split across several processes as the game grows. You host them wherever you like.

How the Servers Fit Together

Planning something large? Talk to us about your architecture.

Start Building
Your World

Networking is part of every install. No extra packages, no separate SDK.