DarkRift - Fast and Flexible Cross Platform Networking

What is DarkRift?
DarkRift Networking is a fast and flexible networking solution for server - client model multiplayer games.

DarkRift takes a lower level approach to networking in Unity than RakNet but still hides you from the complexity of the underlying sockets. Messages are sent between the server and clients in an email like fashion using a tag and subject to identify the message content meaning the bandwidth used is kept to a minimum.

For advanced users you can embed your server into Unity builds to utilise Unityā€™s physics and pathfinding or any other asset you want. Fancy running it on Linux as well? We support that!

How about an authoritative server?
Running server side code is as easy as dropping a .dll file into a folder. If we donā€™t already have a plugin that fits your needs in the plugins thread then you can delve into our serverā€™s inner workings and rig one up in no time at all. It only takes 20 minutes to complete our plugin tutorial.

If you need persistent storage for your game then DarkRiftā€™s database integration will make your job much faster. Add the database connector plugin for your choice of DB and your plugins will be able to run SQL commands through the generic wrapper without even adding another reference to your code.

What about underneath?
Serialisation is completely automated in DarkRift using .NETā€™s powerful BinaryFormatter meaning you can send any serialisable object across the network in a single line of code. However, if you feel you need more control over whatā€™s sent then you can use DarkRiftā€™s new manual serialisation system to easily choose exactly what is sent and bypass the automated serialisation.

Both the client and server APIs are simple and lightweight. If you want to receive data then you latch onto an event, if you want to send data you call a method, if you want to know when someone disconnects then thereā€™s an event for that, if you want to kick someone off because you donā€™t like them: thereā€™s a method for that too!

Whatā€™s new with DarkRift 1.3?

  • Official Linux support via Mono!

  • Unity embedding so you can use Unity physics and pathfinding in your servers!

  • Comments in configuration files (finally).

  • Multithreading in the client API!

  • Bug fixes.

  • Added new demo of custom serialisation.

Where can I get it?
DarkRift is available free on the Asset Store Here up to 20 users, if you want more then get a Pro or Extreme license.

Read a great review and comparison of networking solutions here!

If you have any questions Iā€™ll happily answer them :slight_smile:

More help!
There is also community run Discord channel that everyone is welcome to join here!

Jamie

4 Likes

DarkRift is as accessible, easy to use, and fast as server solutions can get. I was able to rapidly set up a lockstep server shown here: The Lockstep Framework - Unity Engine - Unity Discussions. I recommend it with all my heart and can assure you that DarkRift will satisfy you more than any other networking solution if you put in some work - because DarkRift is whatever you design it to be.

3 Likes

Hi, um. Iā€™m redirected here from the old thread.
So, well. Iā€™m a noob here both in programming and unity.
Iā€™ve been trying out DarkRift for a while now and Iā€™m trying to run two instances of Unity for networking test, but it seems like DarkRift is paused when the game is not on foreground.

I mean, for example, just call A as the first instance of Unity, and B as the second. Iā€™m moving the character using Horizontal keyboard axis.
When Iā€™m pressing a or d on A, and sending it to B, B is not receiving the message (the character stays still).
Then I tried pressing d on A, and quickly switched to B, and B did receive the axis, it moved.
But then it didnā€™t update. If what B received was 1, then it stays 1, and it continue moving even though it has stopped on A.
Then I switched back to A and the axis on A becomes 0 because I didnā€™t press either a or d. But the object on B still moves, until I switched again to B and then it stops (the axis becomes 0).

Is this a bug or was it really intended to be like this?
I mean, if the player accidentally minimized the game then his game client will be ā€˜pausedā€™ and so does his character on the other clients right?

Thanks before :slight_smile:

Hi Linearch, welcome to the forums :slight_smile:

Its a default in Unity to pause the game when itā€™s not in focus, you can change this in Edit ā†’ Project Settings ā†’ Player ā†’ Resolution and Presentation ā†’ Run In Background :slight_smile:

Jamie

Oh, it works :).
Thanks for the fast reply, and sorry.
Idk why but I didnā€™t need to change this when using PUN and uLink so I thought it was like that by default, haha.

May I ask again?
Will it affect the networking performance if I put too many receivers in a client?

You can ask as many times as you like! :slight_smile:

Iā€™m not entirely sure what youā€™re asking, do you mean the DarkRiftReceiver script or do you mean latching onto the data received event (for processing the data yourself). If you mean the former then you should only ever have 1 DarkiftReceiver and that will handle all the messages; however I assume you actually mean the event which, given too many callback procedures, could slow it down but I doubt you will have any problem. You could always use the Profiler to see if itā€™s causing your game issues :slight_smile:

Jamie

I meant the script. The one with DarkRiftAPI.Receive(); on Update(). So I should only have one GameObject with DarkriftReceiver attached to it for each scene in the client? Mind explaining why?
I tried putting two receivers, one in the ā€œScriptsā€ GameObject and one in the playerā€™s character, it didnā€™t give me any error though I doubt it doesnā€™t affect the networking performance.
About sending messages, itā€™s alright to do it in every synced GameObject right? Or should I have relayed (not sure if Iā€™m using the correct word for it) it through the ā€œScriptsā€ GameObject too?
Thanks :slight_smile:

Also, I need some advice on debugging. Iā€™m building a plugin and getting some null reference exception in the serverā€™s cmd window. Though the game works fine without any error. The server doesnā€™t tell me which line it is from. The error showed when a player joined, so I tried printing some log on the script on parts that should be called when player joined, and they all printed just fine but the error still shows after all log is printed. The error spammed a few times for 1-2 secs after the player joined.
Thanks again :slight_smile:

The call to DarkRiftAPI.Receive() enters a loop internally that removes packets of data from the sockets, decodes them and calls the received event until there is not more data left to process. if you make a second call to Receive() then, chances are, there wont be any data that needs to be processed so it will simply exit. I doubt there will be any performance issues by calling it twice but it is simply unnecessary to and could make your code a little less maintainable.

Iā€™m not entirely sure what you mean but you can send from any point in your code (including from other threads and coroutines AFAIK); thereā€™s no technical limitations as to when you can send. Sending from a single script may make your code a little easier to maintain but overall I donā€™t see any reason you couldnā€™t send from any gameobject at any time.

Could you attach the log file for the error (found under Logs ā†’ ā†’ .txt)? If you canā€™t find the source of the error then it could be a problem in the server and the log file will help, otherwise I may be able to help more with it anyway :slight_smile:

Jamie

Ah, is that so. Iā€™ll just use one receiver then.
Anyway, hereā€™s the log file. I donā€™t think it will be helpful, though.

2190653ā€“145346ā€“13-18-54 PM.txt (2.94 KB)

Youā€™d be surprised, seems like it is an internal error (though it could be caused by an external problem). Iā€™ll look into it and prehaps add a little more detail to my error reports in future :slight_smile:

Thanks :slight_smile:
Well, they donā€™t appear if I donā€™t use my plugin so I think it was caused by my plugin.
I think it was because the game hasnā€™t fully loaded but the server was trying to send message to it. Because when it happened the play button hadnā€™t glow blue yet, and it stops spamming when I can finally play the game.

I used both DarkRiftAPI.SendMessageToServer and DarkRiftAPI.SendMessageToID from the client,
and both ConnectionService.SendReply and DarkRiftServer.GetConnectionByID(ushort).SendReply from the server,
and I called DarkRiftAPI.Connect() on Start(), if that may help.
Iā€™ll send the script if you need it for debugging.

Hmmm that information is useful thank you :slight_smile: What is your plugin doing to the data when it throws the exception? Is it anything different to when it doesnā€™t throw the error? Are you using onData or onDataDetailed?

Anything can help and seeing your code may answer a lot of those questions :slight_smile:

Jamie

Right, I donā€™t know what my plugin is doing to the data when it throws the exception. I mean, it doesnā€™t tell me which line caused the error, and the game runs fine without any errors as I stated before. And I tried to write logs and they all print fine but it still throws exception in the end.
Iā€™ll send you the script then, since its too long and messy to be pasted here haha.

Ah, also, Iā€™m using onDataDetailed and OnDataReceived (server)

Sent

Jamie,

Looking into a bunch of networking solutions for our game and I have a few questions about DarkRift. I like the simple API of DarkRift and Iā€™m hoping to use it. Iā€™ve played with the free versionā€™s demos and reading through all the docs. However, Iā€™m still not sure what the architecture of DarkRift is compared to others. What Iā€™m seeing is a different way of doing Unityā€™s Network.RPC() and various network callbacks on MonoBehavior, like OnConnectedToServer(). I know thatā€™s simplifying your work and I donā€™t mean disrespect. Itā€™s hard to summarize what DarkRift does in one sentence :slight_smile:

For example, in these cases below, how would DarkRift handle it:

  1. I have multiple enemies in the world, all need to be synced between server and client. Unity handles this with a NetworkView so that ā€œenemy on top of the treeā€ on server is sending messages to only ā€œenemy on top of the treeā€ on all the clients. Iā€™m not seeing this unique ID in the DarkRift documentation and so I was wondering how that would be handled.

In the CubeDemo, I see the CubeMoveā€™s cubeID, but in OnDataRecieved() itā€™s checking this number to make sure the message is filtered to the specific cube. If there was 10,000 cubes, every cube would get that message and check itā€™s cubeID. Thatā€™s very inefficient to be sending data to all the cubes.

  1. Lobby/Room. How would DarkRift create a Lobby/Room concept? Usually this is done in the server, but the server seems to be a closed box. Is this where the Server Plugins come in? If so, how does the Lobby keep track of all the players? Can Plugins talk to the Server about player info? Or are the Plugins written like the client and need to listen for onPlayerConnect events themselves? What is the Server actually doing other than forwarding packets to all clients?

Those are the two biggest things I am trying to figure out in DarkRift. Below is a bunch of small questions:

  1. Does DarkRift.exe only run on Windows? Does the Pro/Extreme version get a OSX version?
  2. Does Pro/Extreme come with source code to the server (DarkRift.exe)? Is the similar to Unityā€™s MasterServer/Faciliator?

Really nice work. Keep it up.

Thanks!
Ted

Hi Ted,
Glad youā€™re considering DarkRift!

As youā€™ve noticed DarkRift is sometimes hard to compare with the other networking solutions because itā€™s not as high level as UNET or Photon; in fact I think the best way to describe it is about midway between the high level solutions and the underlying sockets theyā€™re all based on, it takes away the serialisation and handling of IDs etc. but leaves you without NetworkViews and RPCs etc. DarkRiftā€™s events are essentially stripped down RPCs that (if I recall correctly) are much faster and lighter the Unityā€™s and so are a bit more suitable for synchronising things.

In your first example DarkRift gives you a few ways to address this, the standard (actually thereā€™s not really any standard ways of doing things in DarkRift!) is to assign each an ID and then for them each to check whether data is for them as you saw in CubeDemo but you are quite right in that for large numbers of cube this would be very bad. I suspect that this would work fine for ~500 cubes depending on how much processing each cube has to do in checking the data but with 10000 I would use a hash table to distribute the data to only the correct one: eg. A manager receives the data, inputs the ID into a hash table and receives the instance of the cube with that ID and then passes the data to said cube. Whilst I canā€™t be sure, I suspect Unityā€™s RPC system uses a hash table to distribute the RPCs correctly as that should be the most sensible way to implement it.

If you know big O notation the cube demo runs in O(n) but a hash table would reduce that to O(1).

In regards to the Lobby System question I am currently working on one to be added to the Plugin thread which should be out with the next version (maybe a month or so?). A few people have built there own Room systems and I think the lockstep plugin in said thread has a simple one already implemented.

You are quite right in that the server is a closed box and for the most part simply forwards packets on to other clients (it does more behind the scenes such as the serialisation/deserialisation, ID allocation, the API, plugin management etc.) but the advantage of that is that no game mechanics are set in stone into the server. For example with photon you have to use the room system whether you want rooms or not but with DarkRift the idea was that this would be a plugin you could add or remove depending on whether your game actually needed rooms.

Plugins and clients are fairly different. Both use similar event systems but plugins have a large API to change the server with and can change/intercept/destroy/create messages, change the distribution, access databases and in general plugins know everything whilst a client should know only what it needs to. A room system, in a fairly abstract way, would remember which room each connection is in and then instruct the server on any further action it should take (eg. not transmitting data between rooms).

For your other two questions:
DarkRift is .NET and so will run on OSX and Linux via Mono, I think you need to enable the beta garbage collector though (I donā€™t do Linux/OSX stuff!).
I suspect if you do buy the extreme version Iā€™m probably happy to give you the source code! :stuck_out_tongue:

Jamie

Hello,

I am looking for network solution for my game and I am wondering if DarkRift can be used to make a MarioKart like game.
I seen DarkRift Server is a standalone program so how physics collision can be resolved ?
Shoul I set one client as authoritavie server and manage the physics and propagate the result through the DarkRift server ? I fear for latency problem with this solution.

thank.
Tazack.

Hi Tazack,
Definitely could! I agree about your worries of latency, although running both on the same machine would reduce this hugely and I donā€™t think you would need to worry about of much about it. The code to manage it may not be as fun however!

Alternatively if you wait about a month until the next version that will allow you to embed a DarkRift server within Unity and will make your problem way simpler!

Jamie

So see you next month :wink:

1 Like

Hello Jamster !
I used Dark Rift for a real time application and itā€™s working very good :slight_smile:
I had 2 questions :

  • Is DarkRift API can be used in WebGL export?
  • Did you ever deployed a server in a web host machine and try access it via internet? I just tried and Iā€™m meeting some issues (surely network port or something). I can connect but I donā€™t receive any message.

Thank you for the development of that toolā€¦ Really it changed my life !