Search Unity

Client disconnects when calling .Connect

Discussion in 'Multiplayer' started by darthtelle, Aug 1, 2017.

  1. darthtelle

    darthtelle

    Joined:
    Jan 7, 2014
    Posts:
    114
    Code (CSharp):
    1. private void ConnectToServer()
    2. {
    3.      string hostIP = /*GET HOST IP*/;
    4.        
    5.      // Connect to the server.
    6.      m_ClientData.m_ClientInfo.m_ClientObject.Connect(hostIP, k_ServerPort);
    7. }
    I'm getting some game-breaking behaviour when trying to connect a client using UNet. I'm using NetworkServer and NetworkClients in UNET, and I have my own NetworkManager. Due to the nature of the game, using the super HLAPI stuff wasn't applicable.

    The project I'm currently working on is on Steam and another console, and the behaviour is similar on both platforms. When a player invites another player to the lobby or a player chooses to join that lobby, when my code gets to the above line (.Connect) I get one of a few different results:

    1. After the client calls .Connect() on the client object (which is of type NetworkClient), it gets a Client disconnected message out of the blue. Unfortunately, there is no other information provided with these logs (turned LogFilter up to Debug) to let me know if there was a crash or an error or anything. I've provided a screenshot of the console below.

    connecterror.png

    2. I get the following error in the console:
    3. It works. Client joins lobby.

    Does anybody know why UNet would stop allowing a client to connect? The host is unaware of any failed attempt by a client to join and is sitting in what I can only assume is a valid lobby. I assume that because sometimes it works.

    Using Unity 5.6.2p3.