Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Unity 2017.2 beta is now available for download.
    Dismiss Notice

DarkRift - Fast and Flexible Cross Platform Networking

Discussion in 'Assets and Asset Store' started by Jamster, Apr 20, 2015.

  1. KHRZ

    KHRZ

    Joined:
    Mar 2, 2013
    Posts:
    54
    WolvBoar, this was answered above.

    Again it is a bit early for me to say, our plan is to have cloud hosted servers that will be able handle users. But we are not massive (like Blizzard) so the user hosted servers seems like a decent feature (like in Team Fortress 2, most servers are user hosted). It is a bit of a future concern, that may not be relevant (modding is common in Team Fortress 2, but hard to say if this would possibly be a thing in our game). But maybe if some user community was really ambitious about this sort of thing, they'd buy a license themselves.
     
  2. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    @WolvBoar really you can't distribute the server so it's an unfortunate no, I'll certainly look into different options about what I could do - considering people seem to want this - but the best approach is to do as KHRZ suggested and run your own servers that people can connect to. DarkRift isn't particularly heavy on the processing and if your game logic isn't too taxing I would expect each server to be able to run around a couple of hundred players at a time, hopefully more, so it shouldn't cost too much.

    Sorry :/
     
  3. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    So I've recently been playing around with DarkRift's serialisation; currently you only have the choice of manual serialization which is both very fast and very compact or Binary serialization (using the .NET BinaryFormatter) which is both very slow and very uncompact :(

    So after a little bit of fiddling around with an old design I've make my own binary serialiser which simply takes an object and serialises it using the manual serialisation system. It's fairly primitive in it's method of choosing what to serialise, it just picks out the public members, but I plan to add some attributes or a special interface for it.

    The stats of 10,000 serialisations and deserialisations compared with the same on a binary formatter are pretty impressive:
    Capture.PNG
    So hopefully I'll be able to remove the one major bottleneck in DarkRift :)

    This wont be in the next version because it doesn't quite fit with the current API, however I'm hoping to do a complete overhaul for DarkRift 2.0 which will probably be released in the summer :)

    EDIT: I should explain the image, the stream lengths are the number of bytes in each object serialised, the times are the time it took to do all 10000 serialisations/deserialisations. Both objects are fairly simple with the second containing a reference to the first as well. I'll try and run some more complex objects once I've cleaned up the code!
     
  4. KHRZ

    KHRZ

    Joined:
    Mar 2, 2013
    Posts:
    54
    I'm scratching my head a bit with some errors the server is throwing, "DarkRiftReader is not marked as serializable", which apparently means a reader is attempted to be serialized. I've looked at all my readers and I don't do this. All I can tell is it has something to do with me decoding a message the server is receiving, and sending a reply with ConnectionServiece.SendReply. Do you have any tips?

    EDIT: OK I seems to have found why the issue happens. In my message to the server, I included an empty DarkRiftWriter as the data object, and I never used it for anything. The error doesn't happen when I remove it and just send some empty string. Is it a requirement to always perform the reading with a DarkRiftReader when you have sent a writer? Must the writer not be empty, or must you read all the data? Should it not really cause an error?

    [Error] System.Runtime.Serialization.SerializationException: Typen DarkRift.Dark
    RiftReader i samlingen Transmission, Version=0.0.0.0, Culture=neutral, PublicKey
    Token=null er ikke merket som serialiserbar.
    ved System.Runtime.Serialization.FormatterServices.InternalGetSerializableMem
    bers(RuntimeType type)
    ved System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Typ
    e type, StreamingContext context)
    ved System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMember
    Info()
    ved System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerial
    ize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context,
    SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter
    objectWriter, SerializationBinder binder)
    ved System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(
    Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerO
    bjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter obj
    ectWriter, SerializationBinder binder)
    ved System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obj
    ect graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
    ved System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(
    Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
    ved System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(
    Stream serializationStream, Object graph)
    ved DarkRift.Transmission.TransmissionProtocol.EncodeMessage(NetworkMessage m
    sg, Byte version)
    ved DarkRift.Transmission.TransmissionProtocol.EncodeMessage(NetworkMessage m
    sg)
    ved DarkRift.ConnectionService.ProcessDataItem(Object context)
     
    Last edited: Dec 5, 2015
  5. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    Hi KHRZ,

    Sorry about the slow reply, I've been at a tournament.

    You're quite right about what's causing the error. Essentially your server is handing your plugin a DarkRiftReader but you aren't doing anything with it in your plug in so when it comes to serialise the data again to send to the other clients it finds that the data in the network message is still a DarkRiftReader which isn't allowed. There's a static DarkRiftUtilities helper class with a method to convert readers to writers which will help you here. If you don't do anything with the data in your plug in and it's a DarkRiftReader then pass the data through that :)

    Again sorry about the delay, I hope that helps.

    Jamie
     
  6. KHRZ

    KHRZ

    Joined:
    Mar 2, 2013
    Posts:
    54
    Another question. Do you know if Windows/Unity/other programs can lose packets during alt tab? Sometimes it seems if I alt tab during scene loading of my game, it will miss a packet. (Running a local DarkRift server so the packet should be guaranteed to arrive). So could it be either Unity or Windows loses it while TCP register it as received? Or does it have to be an error in my program to throw away the packet before being ready after loading? I am sending a message to the server after supposedly having loaded for it to start sending stuff, however it still on the loading screen from the old scene (but it usually works). Just want to make sure these packets are guaranteed to arrive 100% guaranteed to the program even if you alt tab and what not.
     
  7. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    I've never heard of alt-tab doing anything like that... I'm fairly sure that the window manager implements alt-tab functionality so that should have nothing to do with packets being dropped.

    As far as I know it should be guaranteed for all packets to arrive. Though I'm not sure what would cause that behaviour... :confused:
     
  8. reese01

    reese01

    Joined:
    Oct 21, 2014
    Posts:
    21
    Does the game continue to run or is paused while in the background? If not, try checking the "Run in background" option under player settings.
     
    Jamster likes this.
  9. KHRZ

    KHRZ

    Joined:
    Mar 2, 2013
    Posts:
    54
    The problem happened less after I switched to running in background, can't remember for sure if it still happened afterwards. So next time if it happens again, I will investigate properly... But I can see my game is still on the loading screen after the server has started sending when I should be finished loading (It seems monobehaviour Start() function is run already during scene load. It is even worse with the onSceneLoaded function). So maybe if the DarkRift receiver is not running it's update() function until a bit later, it may miss a packet? Or will all packets lie waiting when the update function starts?
     
  10. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    The DarkRiftReceiver wont pick anything up until Update first gets called (after Start has finished) as you say. The packets should be queued by the OS (actually DarkRift will be decoding them while your level is loading) but none should ever be lost :confused:

    From what you've written it sounds like you're sending a message in Start to trigger the Server to send a large amount of data back. If that's the case then you could try sending that first message from the first Update call (setting a flag to say it's sent) or maybe or try counting the number of messages sent on the server and the number of times OnData is called in the receiver. Also if you're assuming that data arrives in the order it's sent with DarkRift... don't... :oops: DarkRift is heavily multi-threaded which means data that takes a short time to serialise could end up in front of data that takes a long time to be serialised - that could explain why it only sometimes happens.
     
  11. Linearch

    Linearch

    Joined:
    Apr 1, 2015
    Posts:
    25
    Hi, here I am again after so long.
    I'm trying to use the embedded server for android build, but it doesnt seem to work.
    I was getting /Logs no permission error, and enabling external data write fixed it. Though I'm still unable to get the server to work. Theres no error now but it still wont work
     
  12. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    As I've said to a few people, the server side code isnt meant to be distributed, it's only tested on platforms you'd usually run a server from (eg windows/Linux).

    I would guess it's because you don't have access to Sockets on Android with out the android pro license (though I vaguely remember this was lifted so I'm not 100% sure). Alternatively if could be due to NAT traversal issues to which, as the server wasn't designed for Android, I honestly have no idea how you would go about fixing... You'd probably need some form of relay server but DarkRift doesn't support this.
    :confused:
     
  13. Linearch

    Linearch

    Joined:
    Apr 1, 2015
    Posts:
    25
    Oh, right. I forgot about that one. I thought that since it could run in Unity (embedded) it'd work on any platform supported by unity, haha. There was no error message or anything, so, yeah.

    Was trying to use it for LAN multiplayer via wifi tether but ok.

    Thanks for the fast response as always :)
     
  14. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    Sorry about that, it is simply down to the fact DarkRift is designed for cloud deployment... :confused:
     
  15. KHRZ

    KHRZ

    Joined:
    Mar 2, 2013
    Posts:
    54
    Seems I found a legit crash this time. It happened when I connected to it after a long time (or maybe it's just because I alt tabbed to it's window). I'm thinking it's because I've had my laptop in sleepmode and awakened it after while DarkRift was running. (Many programs crash due to this).
    [​IMG]
     
  16. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    Ehhhhh... Interesting... :p

    I'll look into that :p
     
  17. vitaliy1

    vitaliy1

    Joined:
    Dec 16, 2015
    Posts:
    2
    hi cool server but how to change port ?
     
  18. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    Take a look in the settings.cnf file :)
     
  19. vitaliy1

    vitaliy1

    Joined:
    Dec 16, 2015
    Posts:
    2
    ok many thanks very very good asset:)
     
  20. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    I need some help with this because i don't quite understand the demos that come with the free asset

    Things that i don't understand:

    - Why are we setting our position when we should set other players position? http://prntscr.com/9gh8s0
    - What's the difference between onData and onDataDetailed

    And i have read all the PDF files and still i dont understand
     
  21. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    In the cube demo that script is attached to each of the cubes, so each cube checks to see if it needs to move and if so moves. It instructs the others to move in the OnMouseDrag routine :)

    onData and onDataDetailed have different signatures for the methods that it calls, in onDataDetailed you are also given the ID of the sender :)

    Hope that helps :)
     
  22. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    Ok thnx bro i apretiate it, and i think you should add more comments to the demos
     
  23. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    One more question:
    Do i need to disable my character controller and camera and then re-enable it when i join the server?
     
  24. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    Depends what you want to achieve. Doing that will cause your screen to be blank until you join the server, you could just disable the character controller and display a GUI item saying "Connecting..." if you wanted to make it more obvious what's happening. It's all up to what you want to happen whilst it connects, there's no technical reason :)
     
  25. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    i dont want to achieve nothing im just wondering if it happens the same thing with UNET where you rotate and move and the other players do the same its like an eco
     
  26. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    by the way, how do i asign network IDs when a new user joins the server?
     
  27. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    i see nevermind xD
     
  28. Hunkofsteel

    Hunkofsteel

    Joined:
    May 13, 2015
    Posts:
    20
    Is the setting for the amount of connected people in the config file for the amount of people currently connected? In my debugging sessions, I have encountered a situations where I'm the only client connected and when I try to connect with my other client the server comes up with the limited amount of connections thing.

    To clarify, this is after I've connect and disconnect to the server several times. During the time when I connect with the error, I had only one client connected.
     
  29. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    The setting in the config file is the maximum amount of people that can be on the server at any one time (ok so I did just find a glitch that means the value set includes the server...).

    I can't recreate it on my end (setting the value in config to 3 means the 3rd client to connect will be rejected as expected (with the bug at least)). Can you tell me if it's reproducible or if it's something random triggering it? Or give me detailed instructions how to cause it myself? It could be a glitch in the server :oops:
     
  30. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    Hey Jamster,
    Is there anyway i could implement teams? Do i need to code a server plugin or can i just check team ids on the client-side
     
  31. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    Another question.
    What about game modes? server plugin?
     
  32. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    First question: You can do either, a server plugin might be a better option as you'll be able to verify the teams and you'll be able to manage them even if clients disconnect.

    Second question: Dunno, depends what your game is... Chances are it's going to be a mix of both...
     
  33. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    can i catch the client disconnect event in plugins?
     
  34. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    ConnectionService.onPlayerDisconnect ;)
     
  35. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
  36. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    Hey Jamster, im having a hard time implementing health in my game and i need your help bro
     
  37. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    How so? What type of game are you making? What's the problem? You'll have to give me some more details if I'm going to be able to help ;)

    I can help with the DarkRift side of things here but if its general Unity you're probably better off creating a new thread :)
     
  38. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    im making a multiplayer WW2 first person shooter.
    My problem is that i dont know how to make the SendMessageToOthers thing

    http://prntscr.com/9i1dxg
    http://prntscr.com/9i1eia

    this is what i have at the moment but it does not work.

    Please help me
     
  39. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    What's wrong exactly? Does the health not decrease? Does it not die? Does the server show data passing through if you set logData to be true?
     
  40. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    it dies for the person that shoots but it doesnt update for the other clients
     
  41. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    The thing is: i am sending the data from a different network id than the person that i shot maybe thats the problem
     
  42. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    I just found a bug - http://prntscr.com/9i2mkk
    This happened because i connect, disconnect and then connect again with the same client/ip address. idk why that happens
     
    Last edited: Dec 24, 2015
  43. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    Hang on. Set logData to true in settings and tell me if your die message reaches the server. I take it you can see their movement and that you've put a DarkRiftListener in the scene?

    The doesn't look like a bug in DarkRift, DarkRift should never destroy an object so that looks more like it's a problem with your code o_O
     
  44. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    let me check sec
     
  45. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    idk about the error with the connect/disconect/connect i have to figure things out but i think the health is a problem in my code can you help me? if you use skype add me: sniper-fun99
     
  46. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    Seriously, set logData to true and see if the server is getting the message, then you will know roughly where the problem is.

    I would skype except it's Christmas Eve here I'd personally I'd rather spend it with family :p
     
  47. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    i did it receives but im having a problem its not destroying the gameobject
     
  48. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    812
    Do you have plugins in your server? If so check the message gets through using a Debug in your receiving method :) If not double check your tags are the same on both sides :)
     
  49. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    im not using plugins for the health
     
  50. GuilhermeStrice

    GuilhermeStrice

    Joined:
    Dec 8, 2015
    Posts:
    23
    its still not working the damn health

    i can't figure this out help me