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