I am learning about networking for game development and need some insight.

My knowledge of Unreal Engine is that it uses RPCs and replicated variables for actors. I also know that Unity has Networked game objects, which also have RPCs and networked variables.

It seems that these object-based network implementations utilize a single class for networking between servers/clients. If there is code specific to either the server or the client in the class, then a conditional is used to determine if we are on the server or the client before executing some blocks of code.

From past software development experience, I assumed there were separate files for each object, such as one on the server, client, and maybe a shared class that both could use.

I'm confused on which implementation to use. Are there specific situations where you would use one over the other? Is a single class more suited for gameObjects/Actors? Is the multi-file approach for server/client better for large systems?

I'm hoping to get this confusion cleared up.

  • \$\begingroup\$ You can as well have a host, which is both a server and Client in one. As for not having server code in the client, you can use a build annotation to exclude code blocks \$\endgroup\$
    – Zibelas
    Commented Dec 23, 2023 at 7:57
  • \$\begingroup\$ There's middle option, which is to have one class that uses conditional compilation to compile into one of two variants depending on whether you're compiling the client or server executable. That lets you specialize client-only/server-only details, without code duplication for any parts that are common to both, or complex code structures needed to keep the client-server-shared parts inter-operating, since as far as either version is concerned, it's "just one class". \$\endgroup\$
    – DMGregory
    Commented Dec 23, 2023 at 11:40
  • \$\begingroup\$ Generally speaking (beyond game dev), from software engineering perspective, one of the things you want to consider when making these choices is what is the relationship between the client and the server, and are these going to be developed by the same person/team or not. E.g., how tightly coupled the client and server are (or should be), is the the server meant to serve a single application, or does it expose a more general purpose API, are the drivers of change different for client(s) compared to the server, etc. \$\endgroup\$ Commented Dec 26, 2023 at 12:37
  • \$\begingroup\$ If the client and the server are very closely related, basically always change together, and are developed by the same person/team, then keeping all the code in the same place is a reasonable approach. \$\endgroup\$ Commented Dec 26, 2023 at 12:39


You must log in to answer this question.