WebGL Client unable to free connections in NetworkServer

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.

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class NetManager : NetworkManager
{
    public bool isClient = false;

    // Use this for initialization
    void Start ()
    {
        #if UNITY_WEBGL
        NetworkManager.singleton.StartClient();
        #else
        if(isClient)
        {
            NetworkManager.singleton.StartClient();
        }
        else
        {
            NetworkManager.singleton.StartServer();
            Debug.Log("Number of Connections: " + NetworkServer.connections.Count);
        }
        #endif
    }

    public override void OnServerConnect (NetworkConnection conn)
    {
        base.OnServerConnect (conn);
        Debug.Log("Number of Connections: " + NetworkServer.connections.Count);
    }

}
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class ClientGUI : NetworkBehaviour
{
    [ClientCallback]
    void OnGUI()
    {
        Rect r = new Rect (Screen.width / 2.0f, Screen.height / 2.0f, 100, 50);
        if (GUI.Button (r, "Disconnect"))
        {
            NetworkManager.singleton.StopClient();
        }
    }
}

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…?

We are having the same problem with our game, any ideas?

which Unity version ?

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.

We are running Unity 5.3.0f4

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.

1 Like

thanks for the video, that’s helpful.

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

It is done and thanks!
https://fogbugz.unity3d.com/default.asp?768030_kc4pi3nntg6fa9lb

Thank you, we will take a look at it.