« The Trials of Networking | Main | Unity, AssetBundles, the WWW and You! »

Networking in Unity: Back to Basics

After the all the issues we had getting Unity to read our own dll and properly wrap our c++ code to c# we decided to use a "proven" solution, that of RakNet. RakNet is a library used by many games and other networking applications that comes with everything preconfigured to create a C# dll using a wrapper utility called Swig. There were even instructions for linking up this dll with Unity, so it seemed like the best option.
After several hours of debugging build errors, followed by linker errors, and reading all that Google had to offer on the subject we found one big flaw. No one, it seems, has ever gotten this dll to compile on a mac, which would leave us back where we started having a working dll only on windows. This isn't to fault RakNet; RakNet compiles just fine using the latest version of xcode, but Unity doesn't support dll's or bundle's that are created on current compilers (they're about 9 years behind in that respect).

As we stared at the lines of red which wouldn't go away it finally dawned on us; why not just use Mono's Socket library? After all, we didn't need the majority of RakNet's feature list, and we had originally been doing everything ourselves from the sockets with our original plugin. Three hours later we were able to get the client talking with the server using the correct endianness. Now we just have to make up for wasted time and start transferring images.