- Home /
LLAPI vs. pure C#.NET sockets
I've been playing with unity's HLAPI a bit, and while it does take care of a lot of the grunt work, it can be confusing at times and just plain too restrictive at others. So now i'm looking at the LLAPI and it just seems like a very thin layer on top of TCP sockets. Is there some advantage of using the LLAPI over C#.NET socket library (I can't see any but I was wondering what others think)?
Honestly I'd go with the native .NET one. Basically unless there is a specific advantage you can pretty much assume .NET does everything as absolutely efficient as possible. After all it was made by the richest organization in the world... $$anonymous$$icrosoft. Unity tends to add unnecessary aspects to things to make it more "beginner friendly" Which after a while of coding in Unity, I am sure you have seen, or will see, a large portion of the main API isn't worth using. Even ScriptableObjects are only worth using due to the fact Unity will recompile them to match any changes to the instanced class. Which in the end, is still just an "ease of use" thing.
Answer by AurimasBlazulionis · Feb 17, 2017 at 12:57 PM
The problem with C# .NET will most likely be is performance. The LLAPI is written in C/C++ and is optimized for the usual use case. And no, LLAPI is not based on TCP. C# part should run on lower performance because most of the stuff happens in C# side and not C++ side.
Not to mention a new/upgraded LLAPI is being made which is able to handle loads of hundreds of megabytes per second.
Answer by WazzaM · Apr 14, 2017 at 05:48 AM
Joe is correct.
As an aside, you can use UDP from C# to roll your own protocol.
-Warwick
Answer by rodeowild · Feb 21, 2017 at 10:13 AM
Edit: I've done some research on my own. The LLAPI is really flexible, manages things you may not want or know how to manage in unity (threads, etc). I've also looked under the hood at the HLAPI (which you can download here). I found it to be a jungle of odd commands and assumed use cases. I'm sure it has uses, and it may be necessary if you're very green, but writing your own classes using the LLAPI, seems easier than, say, learning all about how the NetworkManager interacts with the NetworkIdentity, or figuring out the subtle differences between the NetworkClient and the NetworkServer. As far as performance, it seems like the HLAPI is entirely built on the LLAPI (as the docs say, and of course as would be expected), so you should lose nothing by bypassing it and dealing directly with the LLAPI.
Of course, this is a half-baked opinion, so if you find this and disagree, please let me know :)
Ok so I've done more research on this topic. There are advantages and disadvantages to both protocols. Here they are:
speed - The LLAPI is built on UDP, so it will be almost definitely be faster than TCP, although some test data would be nice to look at. LLAPI wins here.
ease of use - unity makes it really easy to write networking code using the LLAPI (don't use the HLAPI - just DON'T). If you start writing a TCP client and server you start having to deal with concurrency, callbacks, asynchronous functions, and a bunch of other fun stuff. LLAPI is better for quick and easy development. Advantage: LLAPI.
$$anonymous$$odularity - If you build your app using the LLAPI, you are basically stuck using it for the clients, server and any middleware. This is because you are using a Unity specific protocol. Nothing else will be able to decipher your messages. TCP allows for you to take a much more reasonable approach. TCP wins big here.
Basically, as with everything, it depends on what you want to accomplish. Quick and easy, go LLAPI. $$anonymous$$ore robust, go TCP.
For most multiplayer games using TCP would negatively affect the game. Not because of speed, but because each individual position update is rather trivial and would negatively affect the game to be resent if lost after receiving later position updates. UDP automatically handles this by just not resending anything automatically (Unity implements reliable channels as an option on top of this to do its own packet tracking and guaranteed delivery for when that is needed, for commands, rpc's, etc, but most data sent is usually object positions and those are only important at the time they are sent).
TCP though is a guaranteed delivery protocol. I would only use it for turn based games, card games, or similar slow paced games where the majority of packets are important to receive. I would never use it for any game with fast moving objects, or any game where object positions are being synced several times per seconds like UNET is really designed for.