Search Unity

WebGL Client unable to free connections in NetworkServer

Discussion in 'Web' started by kroth, Dec 3, 2015.

  1. kroth

    kroth

    Joined:
    Apr 2, 2015
    Posts:
    10
    I have been working on a WebGL game that uses the NetworkManager. I ran into an issue where the server would stop accepting connections from the clients. I noticed that the number of times I was able to connect was one less than the Max Connections specified in my NetworkManager. It appears as if when a WebGL client disconnects from the server, the connection is not being freed up.

    I made a simple project to test what was going on. Below is the code for the network manager I used to start the client and server, and the GUI I used to disconnect from the server.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using System.Collections;
    4.  
    5. public class NetManager : NetworkManager
    6. {
    7.     public bool isClient = false;
    8.  
    9.     // Use this for initialization
    10.     void Start ()
    11.     {
    12.         #if UNITY_WEBGL
    13.         NetworkManager.singleton.StartClient();
    14.         #else
    15.         if(isClient)
    16.         {
    17.             NetworkManager.singleton.StartClient();
    18.         }
    19.         else
    20.         {
    21.             NetworkManager.singleton.StartServer();
    22.             Debug.Log("Number of Connections: " + NetworkServer.connections.Count);
    23.         }
    24.         #endif
    25.     }
    26.  
    27.     public override void OnServerConnect (NetworkConnection conn)
    28.     {
    29.         base.OnServerConnect (conn);
    30.         Debug.Log("Number of Connections: " + NetworkServer.connections.Count);
    31.     }
    32.  
    33. }
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using System.Collections;
    4.  
    5. public class ClientGUI : NetworkBehaviour
    6. {
    7.     [ClientCallback]
    8.     void OnGUI()
    9.     {
    10.         Rect r = new Rect (Screen.width / 2.0f, Screen.height / 2.0f, 100, 50);
    11.         if (GUI.Button (r, "Disconnect"))
    12.         {
    13.             NetworkManager.singleton.StopClient();
    14.         }
    15.     }
    16. }
    When you run the client from the WebGL player, the number of connections never goes down after a disconnect, but if you run the client as a standalone, the number of connections does go down after a disconnect. Is this intended, am I not disconnecting correctly in the WebGL player, or...?
     
  2. skullbox_

    skullbox_

    Joined:
    Dec 14, 2015
    Posts:
    15
    We are having the same problem with our game, any ideas?
     
  3. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    which Unity version ?
     
  4. kroth

    kroth

    Joined:
    Apr 2, 2015
    Posts:
    10
    I tested this in 5.2.3p1 when I originally posted. I believe it was still happening in 5.3.1p3, but will have to confirm. I plan on downloading 5.3.2p1 this morning.

    Edit: Just tested in 5.3.1p3 and 5.3.2p1. The issue still happens in both versions.
     
    Last edited: Feb 1, 2016
  5. skullbox_

    skullbox_

    Joined:
    Dec 14, 2015
    Posts:
    15
    We are running Unity 5.3.0f4
     
  6. oddcometgames

    oddcometgames

    Joined:
    Dec 16, 2015
    Posts:
    2
    I have made a video explaining the problem. If you need the project just tell me but it is pretty straight forward. I can reproduce it in both 5.3.0f4 and 5.3.2f1.

     
    kroth likes this.
  7. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    thanks for the video, that's helpful.

    To speed things up, would you mind submitting a bug report with the Unity project ?
     
  8. oddcometgames

    oddcometgames

    Joined:
    Dec 16, 2015
    Posts:
    2
  9. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654