private void OnServerConnected(SocketerClient client, int sourceId, string clientAddress)
        {
            Debug.Log("Server connected to " + clientAddress);
            TCPNetworkConnection connection = new TCPNetworkConnection(client, clientAddress, sourceId);

            serverConnections[sourceId] = connection;
            connection.SetIncomingMessageQueue(inputMessageQueue);
            newConnections.Enqueue(connection);
        }
        private void OnClientConnected(SocketerClient client, int sourceId, string hostAddress)
        {
            Debug.Log("Client connected to " + hostAddress);
            TCPNetworkConnection connection = new TCPNetworkConnection(client, hostAddress, sourceId);

            if (!AttemptReconnectWhenClient)
            {
                connection.StopConnectionAttempts();
            }

            clientConnection = connection;
            connection.SetIncomingMessageQueue(inputMessageQueue);
            newConnections.Enqueue(connection);
        }
        /// <inheritdoc />
        public void DisconnectAll()
        {
            // Make sure the client stops before attempting to disconnect
            // anything else. Otherwise, a race condition could cause the client
            // to automatically reconnect to the disconnected endpoints.
            if (client != null)
            {
                client.Stop();
                client = null;
            }

            if (clientConnection != null)
            {
                clientConnection.Disconnect();
                clientConnection = null;
            }

            foreach (TCPNetworkConnection connection in serverConnections.Values)
            {
                connection.Disconnect();
            }
            serverConnections.Clear();
        }
        private void OnClientDisconnected(SocketerClient client, int sourceId, string hostAddress)
        {
            if (clientConnection != null)
            {
                Debug.Log("Client disconnected");
                clientConnection.SetIncomingMessageQueue(null);
                oldConnections.Enqueue(clientConnection);
                clientConnection = null;
            }

            if (!AttemptReconnectWhenClient)
            {
                Debug.Log("Stopping subscriptions to disconnected client");
                client.Stop();
                client.Connected    -= OnClientConnected;
                client.Disconnected -= OnClientDisconnected;

                if (this.client == client)
                {
                    Debug.Log("Clearing client cache");
                    this.client = null;
                }
            }
        }