Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

NetworkManager Error: Server client disconnect error: 1

Discussion in 'Multiplayer' started by newwise, Nov 2, 2016.

  1. Nikolat93

    Nikolat93

    Joined:
    Sep 5, 2016
    Posts:
    36
    Forget all this nerd S*** and pointless singletons. You just need to give a little bit of a buffer before you call stop host.
    *NOTE* this is specifically for the host id out of bounds error on disconnects.

    public override void OnServerDisconnect(NetworkConnection conn)
    {
    NetworkServer.DestroyPlayersForConnection(conn);
    StartCoroutine(StopNextFrame());
    }

    private IEnumerator StopNextFrame()
    {
    yield return null;
    StopHost();
    }
     
    Last edited: Jan 1, 2019
  2. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Ahh .. @Nikolat93

    were you referring to this:

    You in fact must, absolutely must, have something that keeps track of connections - as it says "anyway". Like, you won't be able to do multiplayer gaming unless you do that. Somewhat bizarrely, Unity does not bother to "do that built-in" so you have to do it yourself - one way or another.

    i.e., unrelated to the specific issue discussed here, you have to do that anyways.

    (You certainly don't have to use a singleton - use any technique you want. On every project I've ever been on, it's just been an ordinary old singleton, though.)

    Hppy new year all !
     
  3. Nikolat93

    Nikolat93

    Joined:
    Sep 5, 2016
    Posts:
    36
    Sorry i wasn't trying to create any confusion or knock your singleton, I was just saying that it's possible to resolve the host id out of bounds error without creating a bunch of extra code. Thanks very much for your informative post and pushing me in the right direction (to avoid the racetrack condition with unet static update).

    This is specifically for my game where when one player exits the match I want the other player to be disconnected. Push the stophost() call to the next frame (when called from host side) and voila, no out of bounds error. You are correct that OnServerConnect and OnClientConnect need to be overriden.

    I tried to strip my code just to share the essential, but left a typo in the process. It is fixed now.

    Thank you for sharing your research, and happy new year!
     
  4. Moitroid

    Moitroid

    Joined:
    Jun 29, 2016
    Posts:
    4
    @Fattie in NetworkDiscoveryClient.OnEnable (line 31 of your NetworkDiscoveryClient code specifically), it says to use localhost during development. But what about after development is done?
     
  5. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    hi @Moitroid , very simple !

    say you have a global variable "developmentOnly"

    IF "developmentOnly" is true, you simply execiute that block of code .....

    ... note at the end of that block of code it "return"s.


    in the normal ordinary situation ("developmentOnly" is false), the computer will simply ignore that piece of code. And then the rest of the code below, does all the work for you, in the normal case!

    All the "normal" code, is, simply, the code below that block.

    That's all there is to it! it's just "breakaway" code structure.

    Here's an example of if-else code structure:

    {
    if (X)
    do something
    else
    do something else
    }

    Here's an example of "breakaway" code structure:

    {
    if (some unusual case)
    {
    do something
    return
    }
    have all the normal code here
    have all the normal code here
    have all the normal code here
    }

    if the second part (the "normal part") is very long, many people use "breakaway" as in the second example. This is common in all languages.

    (Again, it means nothing: it's just code format. You could format it like the upper code example here "if-else", if you preferred.)

    Hope that all makes sense. Don't hesitate to ask anything.
     
  6. Moitroid

    Moitroid

    Joined:
    Jun 29, 2016
    Posts:
    4
    Thank you very much @Fattie

    What about the ip address to use? I know we use localhost for development, but what ip and port is recommended when done with development?
     
  7. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    144
    Years later I would like to revisit this post and perhaps perform a bit of necromancy as the need for networking is far from dead even if UNet has been depreciated. So I ask is Fattie's solution still relevant? Is there a better method in Unity 2019.3+ or the upcoming 2020.+ I would also ask if things change based on mobile deployment or a VR game. Lastly how does the development or production use of local host vary if you will only ever connect by a LAN cable and network switch and never over the web?
     
    wlwl2 likes this.
  8. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    @Giantbean - I actually don't know either!

    Unity were "about to" release their totally new networking.

    When they do that, all of this would be historic information of no value.

    BUT I actually have no clue if they have done that yet! As I have not started up a Unity project for a few months, so I'm not up-to-the-minute. Someone else will have to answer!

    * Regarding your question about LAN-only. You would need to start a separate thread for that different issue. Funnily enough we did indeed do a LAN-only project, and it's tricky. I think I made a post on here explaining the issues. IN any event it's a separate good question. Cheers!
     
    Giantbean likes this.
  9. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    144
    Thanks Fattie.