Пример #1
0
        /// <summary>
        /// \brief Handle all incoming messages for this client.
        ///
        /// This is done using the static MessageHandler.HandleIncomingJsonMessage() method.
        /// When the clients' connection closes, the client will be remove from the connected clients list in the MessageSocketManager.
        /// This method is called in the constructor method of ClientMessageSocket.
        /// </summary>
        private void HandleIncomingMessagesFromClient()
        {
            while (innerClient.Connected && IsConnected())
            {
                var stream = innerClient.GetStream();
                if (stream.DataAvailable && !isCalling)
                {
                    MessageHandler.HandleIncomingJsonMessage(this, GetStringFromNetworkStream(stream));
                }
            }

            // When the connection is closed, remove this client from  the list in MessageSocketManager.
            MessageSocketManager.RemoveClientFromConnectedSockets(this);
        }
Пример #2
0
        /// <summary>
        /// Log the user and client out.
        /// The ClientMessageSocket client is removed from the connectedSockets list in the MessageSocketManager and the connection is removed from the database.
        ///
        /// The LogOut message should containt the following values:
        /// - ClientID: the ID of the table
        /// - ID: the ID of the user
        /// An MissingFieldException  will be thrown if the message does not contain these values.
        /// </summary>
        /// <param name="jsonObject">The LogOut message</param>
        private static void LogOut(dynamic jsonObject)
        {
            // Search for the client in the connectedSockets list of the MessageSocketManager class.
            var client = MessageSocketManager.GetClientMessageSocketById(jsonObject.CLIENTID);

            // Remove the client from the connectedSockets list if it is not null.
            if (client != null)
            {
                MessageSocketManager.RemoveClientFromConnectedSockets(client);
            }
            // Remove the connection from the database.
            var dbManager = new DatabaseManager();

            dbManager.DisconnectGuestFromTable(jsonObject.ID, jsonObject.ClientID);
            dbManager.Close();
        }