First of all let’s talk a little about networking theory. Well basically all you need to do is to connect two or more computers in same network. One of them is a server and the rest are clients. Clients connect to server and generate some actions while players play a game. All you need to do is to synchronize those actions with all connected clients so that any player can see what other players do.
Sounds easy? Well actually not so easy at all in real practice. First of all you need to choose which protocol to use – TCP or UDP.
TCP (Transmission Control Protocol) - all connections are reliable and ordered. All data guaranteed to arrive in the right order. You can just send some information and do not worry about it anymore.
UDP (User Datagram Protocol) is another protocol but unlike TCP, UDP is an unreliable protocol - no any guarantee that all the data packets arrive. There is also no any guarantee of right packets ordering. If you send 5 packets in order 1,2,3,4,5 they can arrive completely out of order like 3,1,2,5,4.
Basically if you plan to make a turn-based latency-tolerant game you should use reliable TCP. But if you want to make some multiplayer real-time action game you need to use UDP. The problem with using TCP for real-time games is that unlike web browsers or email clients these multiplayer games have a real-time requirement on packet delivery, so less delay in checking and resending data packets is the important point here.
We plan to make a real-time multiplayer military tank action game so we need to use UDP and dedicated authoritative server. Let’s take a look which UDP libraries Unity game engine has.
UNET is the native Unity networking library. After checking it I would like to say that this is ineffective mess. It has hi level Api (HLAPI) and low level Api (LLAPI). Considering that the current HLAPI+LLAPI combination is not really stable after 3 years since first release and that these technologies will no longer ship with Unity after 2018.4 it is really not a good idea to use UNET for brand new multiplayer game now.
Unity team promise to make experimental / preview version of the brand new networking tech by the end of the year but I am pretty sure that we can wait for year 2020 until we can really use it in production. They need to learn from Unreal Engine team how to make a good networking. So far they just promise to do it right this time but we all know how long it can take to fix all the bugs.
The major alternative to UNET is the Photon Unity Networking (PUN) but it has limits and a way too expensive for people like me.
Well-known Valve company is currently working on an entire networking back-end that isn’t tied explicitly to their services, but it’s neither complete yet nor is there a C# port of it.
So what we gonna do? I can tell you what. We plan to use our own networking solution based on those two free assets:
->>> Master Server Framework (link) - for matchmaking only.
->>> DarkRift Networking 2 (link) – for gameplay.
I plan to use those free assets as a foundation for networking part of our game project. I will add interpolation, extrapolation and lag compensation. When it more or less ready I'll share my source code somewhere so stay tuned. If you have a better solution for Unity real-time multiplayer programming please write a comment.