title: How to get actual connections count for NetworkServer in Unity
body: <p>I'm going to develop a simple multiplayer for my Unity game project. I've started from HLAPI, but it appears to be vvvery slow on spawning and syncing states, so I've decided to investigate Unity Internet services instead, starting from the basic examples at <a href="https://docs.unity3d.com/Manual/UNetInternetServicesOverview.html" rel="nofollow noreferrer">https://docs.unity3d.com/Manual/UNetInternetServicesOverview.html</a>.
  The problem here is in outdated references, so I'm not sure if the cause of my troubles is my misunderstanding or buggy framework.(</p>
  
  <p>Anyway, I took the first example, started modifying it and can't understand the correspondence between "connections" and "clients" for the server.</p>
  
  <p>Namely,</p>
  
  <ul>
  <li>I do create a match with <code>networkMatch.CreateMatch</code> method.</li>
  <li>Then in <code>OnMatchCreate</code> callback I check the value of <code>NetworkServer.connections.Count</code> - it's 0.</li>
  <li>Then I call <code>networkMatch.ListMatches</code> and see the <code>matchInfoSnapshot.currentSize</code> of created match in the callback - it's 1.</li>
  <li>I check <code>NetworkServer.connections.Count</code> in the same callback - it's still 0 (!!!). I check <code>NetworkServer.localConnections.Count</code> - it's 0 also.</li>
  </ul>
  
  <p>OK, I've presumed that local client doesn't produce any connection to the server (???), let's check it.</p>
  
  <ul>
  <li>Then I call <code>networkMatch.JoinMatch</code> from the same client - it succeed.</li>
  <li>Then I call <code>networkMatch.ListMatches</code> again and see the <code>matchInfoSnapshot.currentSize</code> of my match in the callback - it's 2 now.</li>
  <li>I check <code>NetworkServer.connections.Count</code> in the same callback - and it's also 2 now (!!!) (while <code>NetworkServer.localConnections.Count</code> remains 0).</li>
  </ul>
  
  <p>So, the question is simple - I wish not to add any dumb counter variables, but...
  <strong>how can I get an actual count of connected clients on a server</strong>?</p>
  
  <p>P.S: Simplified script to test:</p>
  
  <pre><code>    using UnityEngine;
      using UnityEngine.Events;
      using UnityEngine.Networking;
      using UnityEngine.Networking.Types;
      using UnityEngine.Networking.Match;
      using System.Collections.Generic;
  
      public class TestNetworkController : MonoBehaviour
      {
          private NetworkMatch networkMatch;
  
          void Start () {
              networkMatch = gameObject.AddComponent&lt;NetworkMatch&gt;();
  
              networkMatch.CreateMatch ("TestMatch", 4, true, "", "", "", 0, 1, OnMatchCreate);
          }
  
          private void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfoResponse) {
              NetworkServer.RegisterHandler (MsgType.Connect, OnServerConnect);
  
              if (!NetworkServer.Listen (matchInfoResponse, 9000)) {
                  success = false;
              }
  
              if (success) {
                  Debug.Log ("Match created, connections="+NetworkServer.connections.Count+" localConnections="+NetworkServer.localConnections.Count);
  
                  networkMatch.ListMatches(0, 20, "", true, 0, 1, OnMatchesListPage1);
              }
          }
  
          private void OnMatchesListPage1(bool success, string extendedInfo, List&lt;MatchInfoSnapshot&gt; matchListResponse) {
              Debug.Log ("Match list received, connections=" + NetworkServer.connections.Count + " localConnections=" + NetworkServer.localConnections.Count);
              Debug.Log ("Match 0 size "+matchListResponse[0].currentSize);
  
              networkMatch.JoinMatch (matchListResponse[0].networkId, "", "", "", 0, 1, OnMatchJoined);
          }
  
          private void OnMatchJoined(bool success, string extendedInfo, MatchInfo matchInfoResponse) {
              if (success) {
                  NetworkClient networkClient = new NetworkClient ();
  
                  networkClient.RegisterHandler (MsgType.Connect, OnClientConnect);
                  networkClient.Connect (matchInfoResponse);
  
                  Debug.Log ("Match 0 joined, connections=" + NetworkServer.connections.Count + " localConnections=" + NetworkServer.localConnections.Count);
              }
          }
  
          private void OnServerConnect(NetworkMessage networkMessage) {
              Debug.Log("Client connected, connections="+NetworkServer.connections.Count);
  
              networkMatch.ListMatches(0, 20, "", true, 0, 1, OnMatchesListPage2);
          }
  
          private void OnClientConnect(NetworkMessage networkMessage) {
              Debug.Log("Connected to server, connections="+NetworkServer.connections.Count);
          }
  
          private void OnMatchesListPage2(bool success, string extendedInfo, List&lt;MatchInfoSnapshot&gt; matchListResponse) {
              Debug.Log ("Match list received, connections=" + NetworkServer.connections.Count + " localConnections=" + NetworkServer.localConnections.Count);
              Debug.Log ("Match 0 size "+matchListResponse[0].currentSize);
          }
      }
  </code></pre>
  
  <p>And it's console output:
  <a href="https://i.stack.imgur.com/fGr41.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fGr41.png" alt="Console output"></a></p>