1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Random disconnects when using matchmaking server

Discussion in 'Multiplayer Networking' started by TerabyteTim, Jul 20, 2015.

  1. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    95
    So for some reason, in an empty scene using only the base NetworkManager script and NetworkManagerHUD script, with a prefab that uses an empty NetworkBehaviour script (e.g. it extends NetworkBehaviour but doesn't add any code), with the NetworkManager set to auto create the above prefab, and the above prefab marked as "local player authority", I'm getting disconnects after a seemingly random period of time with the error "Server event: host=0 event=DisconnectEvent error=6".

    The weird thing is that if I use the "LAN host" and "LAN client" HUD buttons I don't have any disconnect issues. However when I use the online matchmaker to create and join a match, after a few minutes the client will timeout with the above error.

    I've also noticed that sending a large number of NetworkClient.SendUnreliable() over a period of time seems to also cause this disconnect to happen.

    I'm wondering if anyone has any ideas what may be causing this, or if I should submit a bug to Unity. I'm only using the baseline scripts, so I can't imagine what may be going wrong.

    EDIT:

    Oddly enough, when I use my own script for managing the matchmaker and connecting I don't get any random timeouts. However when sending about 30 of NetworkClient.SendUnreliable() per second, after about 2 minutes my client disconnects with the same timeout error.
     
    Last edited: Jul 20, 2015
  2. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    95
    So for some reason my matchmaking code isn't having the problem of just randomly disconnecting. However, I'm streaming voice chat data over the network, and after a few minutes of streaming the client disconnects with the above timeout. I've sent using NetworkClient.SendUnreliable(), RPC's, and Commands, all with the same results. I've also set the channel I'm using to unreliable, unreliable fragmented, and unreliable sequenced all with the same result.

    I'm honestly not sure what could be going wrong here. If I sit there without streaming voice data, I can go as long as I want without disconnects. If I periodically stream voice data I can go as long as I want. But if I just stream voice data for a solid minute or two it times out. I've tried sending small packets 30 times a second, and sending larger packets twice a second, all with the same results.

    EDIT:

    As a side note, if I connect directly between the two clients (e.g. skip the matchmaker, use the IP to connect) then I don't get any disconnect. Also if I simply send an RPC/CMD with a string twice a second I don't get a disconnect either. It's only when sending this audio data that I get issues. But it works perfectly fine for the first 2 minutes, transfer time is under half a second and the quality is clear.
     
    Last edited: Jul 21, 2015
  3. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    Streaming voice data is likely exceeding the bandwidth limit, or on the edge of doing so. Right now we don't have tools to indicate you've been disconnected for that reason but we're working on them as i speak.

    Our bandwidth limit is 4k/second, calculated over the lifetime of the connection. So every second you're connected you can use another 4k, and if you send less than 4k/second that bandwidth is credited to the connection so if it gets spiky and goes over 4k for a short amount of time it wont immediately disconnect.
     
  4. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    95
    Does the 4k/sec bandwidth limit apply to all clients, or does each connected client get 4k/sec?

    Also, is there any way for me to measure my data usage while the application is running?
     
    Last edited: Jul 21, 2015
  5. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    Each client gets 4k/sec, and it's set up to be as fair as possible and let the host use bandwidth against that total since it's probably sending out a lot more data than other clients do. With that in mind you can really think of bandwidth as a per match thing, and the total cap is really 4k/second * (number of clients in a match).

    Right now our backend tools to monitor against this cap and show you the results aren't in place, but are coming. Until then it's probably best to stay away from heavy bandwidth usage like voice but most game data should fall well within these guidelines.
     
  6. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    95
    The only problem is that Unity doesn't offer voice chat out of the box, and the only other couple solutions aren't that great. Is there any way within C# to check the size in bytes of a packet before I send it?