Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

DarkRift Networking 2

Discussion in 'Assets and Asset Store' started by Jamster, Feb 7, 2018.

  1. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    101
    @Jamster buy a pro version, is the room function already available? Do you provide the DLL source code? thank you very much.
     
  2. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Hey,

    Room system will be out in the next version, as will the source code :)

    Jamie
     
  3. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    101
    @Jamster Can you tell me next version about time ?thanks
     
  4. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    I'll give a rough estimate of about 2 weeks. I still need to finish testing the room system and haven't yet started on the source code access so it'll be a while.

    Jamie
     
    LostPanda likes this.
  5. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    101
    thanks jamie!
     
  6. TreSoft

    TreSoft

    Joined:
    May 29, 2013
    Posts:
    3
    Hi Jamie,
    first. Thank you very much for this very great asset.

    I have some problems to find a good concept to automate the development process with this kind of architecture. It would be very helpful if you could share some best practices of how your VS / Unity project structure and configurations are, specially when you work with multiple plugins.

    Thank you
     
  7. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Sure!

    If you're using an embedded server firstly, there are a couple of things I've seen people do:
    1. Some maintain a single project with separate server and client scenes, they then use conditional compilation to ensure no server code reaches the client (for security). This makes automation rather easy but you do need to do a lot of conditional compilation!

    2. Some maintain two separate projects for the server and client with a DLL library containing any common code. This can be easier if you're sharing minimal code between the two but in general I would say is more work. Writing a quick editor script to copy over the latest shared DLL build is probably a good idea here!

    If you're working with the console based server things can be a little messier...
    I would almost certainly have a DLL for shared code and a short editor script to import it into your Unity project with a single menu click. Your plugins can simply reference this project for ease.

    Getting the plugins into the server can be automated in a number of ways such as a quick shell script to copy them all over or by adding an additional post build task to your project config.

    However there's a rather neat, pretty undocumented way of doing things I'd use (which I should probably document aha!)

    DarkRift operates from the current working directory and the configuration allows you to specify an awful lot so that you don't need DarkRift anywhere near your project.

    Consider moving your DarkRift server to somewhere global and adding it to your PATH (windows) so you can then call DarkRift.Server.Console from CMD/Powershell/bash. DarkRift will look for the configuration in the current working directory and will (by default) also create the Logs folder and Plugins folder there.

    In the config you can adjust the Logs folder location to be somewhere different if you want, but more importantly you can adjust the locations of plugins with the pluginSearch element.

    As an example for clarity consider:
    Code (csharp):
    1. C
    2. |-----DarkRift--DarkRift.Server.Console.exe etc.
    3. |-----You----YourProject
    4.                   |---DRPlugins
    5.                   |       |---Plugin 1---bin
    6.                   |       |---Plugin 2---bin
    7.                   |
    8.                   |--Server.Config
    9.  
    With a plugin search path of
    Code (csharp):
    1. <pluginSearch>
    2.     <pluginSearchPath src="DRPlugins/Plugin 1/bin/"/>
    3.     <pluginSearchPath src="DRPlugins/Plugin 2/bin/" />
    4. </pluginSearch>
    5.  
    You can now just cd into C\You\YourProject and call DarkRift.Server.Console.exe to run your server!

    You can also specify the config file path as the first argument if you wanted further customisation like DarkRift.Server.Console.exe ./Config/GameServer.config

    I hope that's interesting information for you and helps you! I'm not sure how many people use it like this so you could be in uncharted territory but feel free to ask more questions about it!

    Jamie
     
    Last edited: Aug 10, 2018
  8. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    DarkRift 2.2.0 has been submitted to the asset store!

    With this comes a heap of good stuff! The Free version gets huge documentation updates, dependency injection in PluginLoadData so plugins can now be unit tested, a redesigned UnityServer component (XmlUnityServer) for better configuration, and of course the usual tonne of bug fixes. The Pro version now gets reference source code , .NET Core support, and matchmaking (beta); plus of course everything in the free version!

    If you want a full list, here's the changelog :)

    ----
    DarkRift 2.2.0
    - Pro version now includes .NET Core build!
    - Pro version now has matchmaking (beta)!
    - Pro version now has source code!
    - Added XmlUnityServer for better configuration in Unity based servers
    - PluginLoadData now supports dependency injection for testing plugins
    - Added configuration reference section to documentation
    - Added documentation for Unity based servers

    - Added LogWriterLoadData for log writers
    - Fixed bool arrays being read back backwards in DarkRiftReaders/Writers
    - Added arrays of IDarkRiftSerializable to DarkRiftReaders/Writers
    - Implemented poetntial fix for server crash when clients conenct and disconnect very quickly
    - Fixed resource leak on client disconnection
    - Standardized Pro labels in documentation
    - Fixed a number of documentation typos
    - Fixed ambiguity in installs and upgrades documentation
    - Fixed a lot of references to 'subjects' in documentation
    - Added ServerSpawnData factory method for XDocuments
    - Fixed bug causing errors when blank commands are entered

    *Note this update will require you to recompile plugins due to a change in the IClient interface*
     
    NoobDoAAA and LostPanda like this.
  9. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    DarkRift 2.2.0 is now available on the asset store!
     
  10. simplezt

    simplezt

    Joined:
    Jun 7, 2018
    Posts:
    3
    hey, I want to use unity vector3 quaternion slerp in server code, is it possible?
     
  11. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    You can use those functions if you use a Unity based server, otherwise there are plenty of alternative implementations of those functions online! :)
     
  12. simplezt

    simplezt

    Joined:
    Jun 7, 2018
    Posts:
    3
    Are there documents for implement Unity based server? Beside that, can you show me some alternative?

    What are scripts in Client/Editor and Server/Editor? What are they purpose? Should I write game logic (plugin) in Darkrift/Plugins folder or create a different DLL visual project?
     
    Last edited: Aug 30, 2018
  13. II_Spoon_II

    II_Spoon_II

    Joined:
    Jun 16, 2018
    Posts:
    146
    Does DarkFit require more networking knowledge than PUN? (noob networker asking)
     
  14. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    They're here :)

    The Client folder contains the files to connect to a server from your game, you will have used the UnityClient component in the tutorial and the examples! The Server folder contains some files you'll use in your Unity based server, essentially you add the XmlUnityServer component and can then write your game logic in MonoBehaviours as per usual :)

    The Editor folders in both contains the custom inspectors for the components.

    DarkRift is a lower level networking library than PUN. I always describe DarkRift as taking more effort to do simpler tasks but not constraining you in more complicated tasks. For someone who hasn't done a lot of networking before I'd probably learn the basics with PUN or UNET etc. first as they have many more tutorials and are less aimed at advanced users :) If you've a lot of programming experience then you could definitely consider DR though :)
     
    NoobDoAAA and LostPanda like this.
  15. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    I'm afraid I've not been the most productive this week!

    The main thing that got done was that I've fully rebased the Network Listener plugins branch onto the latest version (which was as much of a struggle as I imagined...) This still requires a fair bit of testing and documentation but that shouldn't be too much of a chore. I'd also like to get a lot of the improvements you guys have suggested for the DarkRiftWriter/Readers as we can get some good optimisations done there and hopefully make them easier to use in general.

    My lack of productivity was mostly due to taking my friend to Insomnia63 gaming festival at the weekend which required a fair bit of preparation. If you haven't gone, I definitely recommend it!

    Jamie
     
  16. simplezt

    simplezt

    Joined:
    Jun 7, 2018
    Posts:
    3
    Where I will write

    void ClientConnected( object sender, ClientConnectedEventArgs e )

    like in Plugin if I implement Unity based server. In this class?

    [AddComponentMenu("DarkRift/Server")]
    public class XmlUnityServer : MonoBehaviour
     
  17. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    You can write it in any MonoBehaviour :)

    Then you can subscribe to it via XmlUnityServer.Server.ClientManager += YourMonoBehaviourClientConnected where XmlUnityServer and YourMonoBehaviour are references to the instances.

    Essentially, any properties of Plugin are available in the Server property of XmlUnityServer :)
     
  18. OneDragutin

    OneDragutin

    Joined:
    May 10, 2015
    Posts:
    315
    Hello Jamster! What is the maximum size of the message that can be sent? Is there any way to change this?

    I'm having bunch of errors and I think this may be the cause...
     
  19. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Reliably it's about 4GB, though I'm not sure I'd recommend sending that! Unreliably you want to avoid sending higher than 1500 bytes else you risk much higher packet loss rates :)

    What sort of problems are you having?

    (Also apologise for the late reply, I've been away!)
     
  20. OneDragutin

    OneDragutin

    Joined:
    May 10, 2015
    Posts:
    315
    Well it is bunch of errors coming from my server that are most likely telling me that client failed to send response...or server failed to send message.
    I looked through some classes with the hope to find some network customization(related to max packet size) and I didn't find any...
    I didn't investigate this further since I was frustrated and I quickly tried other networking solution. Btw this project was working fine with UNET and since UNET is getting deprecated I am forced to find something more reliable...I wish I got DR2 to work with my project. But lack of customization quickly got me looking for other network solutions.
     
  21. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Sorry you've not had much like with DarkRift! That's not what we want!

    If you have the errors are to hand I'd be grateful if you can copy them here, perhaps I can find a solution for you or at least suggest what's going wrong - and if it's a bug obviously get it fixed.

    The maximum sizes there aren't necessarily a DR limitation; the 4GB is but I'd be surprised if you're exceeding that, but the 1500 bytes limitation is the Maximum Transmission Unit on ethernet. You can send more then 1500 bytes but you have a proportionally higher chance of your message not arriving.

    Sorry you're not having much luck with DR, I hope I can sort this for you :)
     
  22. OneDragutin

    OneDragutin

    Joined:
    May 10, 2015
    Posts:
    315
    How fast can your network handle packets? I am sending them every 0.05 on server and every frame on client.
     
  23. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    DarkRift doesn't have any defined tick rate so it's largely dependent on how much processing you're doing on the server and how many clients you have; if you're just redistributing packets between 2 clients then you'll be able to do that much faster than if you're running Unity's Physics.Simulate() every message for 100 clients for example!

    The 0.05 seconds from the server is 20Hz which is a pretty common for a game and should be easily handled by the DarkRift client. The framerate dependent client side is possibly a problem, you usually want a fixed network send rate so sent from a coroutine/FixedUpdate or using Time.time etc. That side of things is also very dependent on the number of clients you have as well.

    Nevertheless, high message frequency shouldn't be a cause of errors so it would definitely be good to have a look at them! :)
     
  24. TrulyStupidNewb

    TrulyStupidNewb

    Joined:
    Dec 8, 2012
    Posts:
    4
    Thank you so much for the documentation for Darkrift 2 and for the improvements. Loving it so far.

    Does Darkrift 2 support hostname ips, such as myniceipaddress.hopto.org? I know DarkRift 1 supported it.
     
  25. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    I don't think it does actually, it's one of those things that I keep forgetting to add!

    Nevertheless, you can resolve a hostname to an IP address using the Dns class and pass that in :) Though I should definitely make that built in behaviour...
     
  26. TrulyStupidNewb

    TrulyStupidNewb

    Joined:
    Dec 8, 2012
    Posts:
    4
    I don't mind not having hostnames as long as I can use the DNS workaround. Thanks!
     
    Jamster likes this.
  27. TrulyStupidNewb

    TrulyStupidNewb

    Joined:
    Dec 8, 2012
    Posts:
    4
    I love Darkrift 2 so far, but I still have a few questions regarding handling persistent data.

    Do we have a DarkRift 2 equivalence of DarkRiftServer.database.ExecuteQuery(query, params) from Darkrift 1? Or, do we just create the equivalence from scratch in a standard Plugin?

    I see a hidden data folder. Can that be used for persistent data, or should we use SQL?
     
  28. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Hey!

    1. The database integration was one of the few things not to get converted over to DR2 mainly because there were a fair few limitations with it, so yes you'll need to just integrate that into a/your plugin. I believe there's a few pre-existing database plugins floating around GitHub but there's no standard access point or interface anymore.

    2. Yes! Each plugin is given it's own data folder and the path is passed to the plugin in Plugin.ResourceDirectory! It's hard to answer if you should use the folder or a database though, it depends what data you're storing. Really the directory should be used for caching files, or storing settings etc. rather than storing user data.

    Glad you're enjoying it all :) Jamie
     
  29. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Hey all!

    Not a huge amount done this week I'm afraid, I've been up in London with friends and sorting all sorts of other life things as well!

    However, I have done a fair amount on the network listeners, fixing some plugin loading issues and finding a few other areas in it that could use abstraction before release, and I've also started on some of the reader/writer improvements which already significantly reduces the memory allocated when using DarkRiftWriters.

    There's still a lot to do before any release is ready and I'd like to get a few more bugfixes in this release!
     
  30. pierreblanc

    pierreblanc

    Joined:
    Nov 4, 2014
    Posts:
    1
    Hi there,

    I have been integrating DarkRift2 into a project of ours, and i'm running into strange issues.
    The server is stand alone (not using Unity) and i have one to several Unity clients.

    On the server, in the ClientConnected callback, I do send 2 messages to the clients.
    On the client, it seems that from time to time, the messages are not received in the order that have been sent.

    Is that a known issue or is there a design rationale behind it ?

    I haven't tried yet to make a client without Unity to see if this is due to the UnityPlugin provided.

    All the best,
    Pierre
     
  31. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Copying from my response on Discord so everyone can see the answer to your question :)

    Yep, that's intentional. Internally in DarkRift (both sides) there's a lot of multithreading so messages can't be received in a guaranteed order, the reason is to get better throughput and make use of any spare threads
     
  32. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    These past two weeks have seen a lot of work!

    First and foremost, network listeners now only require documentation and they're ready to release! These should be a good addition to DarkRift and should allow you a bit more freedom and even allow things like encryption to be added if you should want it in your projects. However there's some backward compatibility problems such as the server IP and ports moving on configuration and API, it'll be fully backwards compatible for the bi-channel listener (i.e. what DR currently uses) but when you start using more custom things that compatibility wont hold.

    Secondly, DarkRiftWriters and DarkRiftReaders are now near GC free! All Write and Read methods no longer cause any allocation unless resizing the array (but you can preset that so you can avoid that too!) This is a big step in getting the main DR pipelines allocation free, so massive thanks to mirenbhakta on GitHub for the help and advice! You can also now reserve space in DarkRift writers and alter the position writers and readers operate on so you can seek around and defer reading/writing till later in your code etc.!

    There have also been a number of other smaller fixes; these include a small memory leak, logs disappearing if written before plugins are loaded, .NET Core plugins not loading when referencing other dependencies, and some tests that were previously missed now actually get run (as well as more tests!)

    Lastly, I've managed to throw in some other optimizations, the BadWordFilter now uses tries rather than a giant regex, and the dispatcher now has InvokeAsync methods with callbacks to replace InvokeWait which was likely causing some thread starvation issues in Unity servers.

    I'm not sure how much I'll get done over the coming weeks though, I'm starting a new job mid-October and need to remind myself how to program in Java first! I'll try and get all this released before then however!
     
    LostPanda likes this.
  33. Bamboy

    Bamboy

    Joined:
    Sep 4, 2012
    Posts:
    35
    Is there a 'default' usable master/matchmaking server that comes with the paid version? Or is that something I'd have to create and host my own?

    Specifically I want my players to be able to see eachothers hosted servers.
     
  34. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Yep! there's a new matchmaker in the Pro version!

    Currently I'm saying it's in beta just because it's not hugely road tested yet and there's always a chance I might need to make a breaking change, but hopefully that won't happen!

    EDIT: Jus reread your question so I'll add some clarification. You'll still need to host the matchmaking servers yourself and write some logic for registering servers etc.!

    Hope that helps,
    Jamie
     
  35. ViniXPM

    ViniXPM

    Joined:
    Aug 16, 2017
    Posts:
    4
    Hey,
    I'm not very familiar with network programming and things like that but DarkRift was pretty straightforward and I just love it. But before developing other things with it, there are some questions I'd like to ask:

    01. Is the fact that messages aren't received in order able to cause a problem in some specific situation?
    02. Assuming someone has the server IP, isn't it possible for them to download DarkRift and make their own client that sends messages to the server? If yes, how could I avoid that?
    03. Is there any authentication service that's easy to integrate you'd recommend? GameSparks perhaps?
     
  36. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Hey!

    1. Not having ordered packets can be annoying for some applications but in the end you can always add that functionality on top of DR using sequence numbers :) Really the only disadvantage is that TCP already has the functionality but it's lost, so it won't use optimal bandwidth.
    2. It is possible yes, but that's the case with any system! You can avoid it best by encrypting messages but that adds a lot of overhead and isn't yet natively supported by DR, and won't fully stop someone - just make it harder.
    3. I've heard of people integrating with Playfab but not Gamesparks yet; if it allows hosting custom server executables then it's almost certainly compatible :)

    Hope that answers some questions!

    Jamie
     
  37. marmelunder

    marmelunder

    Joined:
    Mar 28, 2018
    Posts:
    2
    I hope this is not true at the moment, as the website is down? What is happening, is the asset dead? I hope not I was just starting out with it ;)
     
  38. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    No, my nginx server had crashed apparently! Happened about midday and the logs all rotated so I've no idea what caused it!

    Sorry about that, should be back now :)
     
  39. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Hey all!

    I'm desperately trying to get the next update out but I'm stuck on a tricky bug basically meaning clients no longer work on .NET4.5! As soon as that's sorted (and hopefully it's just that!) then the next big update will be ready with plenty of goodies for everyone :)

    This week has also seen some work on the new Discord bot for approving posts in the #showcase channel of the Discord server. If you haven't yet seen it then checkout the projects already posted and post yours!
     
  40. ViniXPM

    ViniXPM

    Joined:
    Aug 16, 2017
    Posts:
    4
    Alright, thanks a lot. And sorry for such a late reply!
     
  41. lolclol

    lolclol

    Joined:
    Jan 24, 2013
    Posts:
    154
    shut up!! Seriously ? No ccu limitations and own game lobby system?
     
    Jamster likes this.
  42. ShahriyarB

    ShahriyarB

    Joined:
    Oct 12, 2015
    Posts:
    1
    Is it possible for you to include the .net standard 2.0 build in the next free version release please ? :(
     
    Last edited: Oct 14, 2018
  43. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    I'm afraid not, it's a Pro only feature to encourage people to purchase it! There's already a huge suite of features available in the Free version and this is one of very few restricted only to Pro :)

    If you just need Linux support then consider using Mono instead?
     
  44. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    DarkRift 2.3.0 has been submitted to the asset store!

    Woohoo! This is another huge update with plenty of new stuff to keep you entertained for a while!

    This update includes the new network listener plugins, updates to DarkRift readers and writers to make them near garbage free and also introduce a number of other things you've asked for lately, changes DR to use the server GC, adds NoDelay options on the client, hopefully fixes a major recycling bug, plenty of fixes and performance boosts, and the BadWordFilter plugin now uses tries for a bit more performance!

    Sorry this has taken quite as long as it has, just started a new job (it's awesome) and had some horrendous bugs in the network listeners that needed fixing!

     
    Willbkool_FPCS likes this.
  45. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    DarkRift 2.3.0 is now available on the asset store!

    (Documentation to follow shortly!)
     
    Willbkool_FPCS likes this.
  46. kaaJ

    kaaJ

    Joined:
    Mar 21, 2007
    Posts:
    146
    Good job on DR2, works like a charm...

    Is there a way to run Connect() as a coroutine? It hangs the project when a connection is not available.
    Also, a timeout would be nice.
     
  47. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    You can call ConnectInBackground to connect asynchronously, but there's currently no coroutine support :)
     
  48. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    DarkRift 2.3.1 has been submitted to the asset store!

    This update has a number of bug fixes for the Network Listeners among much more!
     
  49. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    DarkRift 2.3.1 is now available on the asset store!
     
  50. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    962
    Hello all!

    This week has seen a lot of work on DR2! First and foremost, I've been working on the new Inter Server Communication again and most of the internal DarkRift code is ready for that, there's still a significant amount of work to do in building the supporting plugins that need to be present, testing and then documentation but the additional configuration file, connection handling and API for plugins is all done. The next thing to build will be an example database connector that the servers can use to advertise themselves on, I'm currently thinking this will be a Postgres database connector as 1. SQL is always a great reference for anyone building other connectors from it, and 2. I have a fair amount of Postgres experience!

    I've also been busy building out a ping system so that you can calculate round trip time easily in DarkRift. This currently involves marking messages as 'ping messages' or 'ping acknowledgements' which DarkRift then times for you and handles smoothing etc. As an example, if you send a request response style message you can mark the request as a ping message and DarkRift will store the send time, then when you receive it at the other end you can send the response message back with a ping acknowledge and DarkRift will record the round trip time when the response is received! All piggy backing off messages you already send and with very minimal additional code :)

    Jamie
     
    ChezDoodles likes this.