Search Unity

New multiplayer system: persistent connection

Discussion in 'Multiplayer' started by keop, Mar 13, 2019.

  1. keop

    keop

    Joined:
    Dec 16, 2017
    Posts:
    10
    Hello,

    I'm starting with the new Unity multiplayer system from here: https://github.com/Unity-Technologies/multiplayer

    I have a starting setup for my server and all my clients, but I don't know why all clients are disconnecting 30 seconds after connecting to the server.

    How can I make those connections to be persistent?
     
  2. CallMeSpam

    CallMeSpam

    Joined:
    Feb 10, 2018
    Posts:
    19
    The connection is set to timeout after 30 seconds of no activity. When playing with this, I just set up a 'heartbeat' message that would be initiated from the client if 25 seconds went without communication from the server, the server would then send a response. It also allows for timing the round trip communications which can be useful. I believe there is also a place in the code that establishes the 30 seconds and you could lengthen that, but a heartbeat is more reliable.
     
    keop and Joe-Censored like this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Do the heartbeat, but don't lengthen beyond 30 seconds. 30 seconds is a common timeout for UDP in router and firewall connections or translation tables. Meaning if 30+ seconds go by without any packet sent or received, the router or firewall may drop that entry from the table and any future packets coming in won't reach their destination. I'd set the heartbeat smaller than 25 seconds as well, just to allow for a dropped heartbeat packet not resulting in a disconnect (I use 3 seconds, but I'm probably playing it more safe than necessary).

    Note that this is generally a configurable setting on the router or firewall, so it could potentially be set shorter than 30 seconds, but common defaults are anywhere from 30 seconds to 10 minutes.
     
    keop likes this.
  4. keop

    keop

    Joined:
    Dec 16, 2017
    Posts:
    10
    Ok, thank you for your fast replies!

    I'm going to follow your suggestions and create a custom keep alive/heartbeat system.
     
  5. ballshe

    ballshe

    Joined:
    Mar 19, 2019
    Posts:
    1
    Hi CallMeSpam,
    However, how to create a heartbeat system?