/// <summary>
        /// Sends a CloseSession message to a client.
        /// </summary>
        /// <param name="reason">The reason.</param>
        /// <returns>The message identifier.</returns>
        public virtual long CloseSession(string reason = null)
        {
            var header = CreateMessageHeader(Protocols.Core, MessageTypes.Core.CloseSession);

            var closeSession = new CloseSession()
            {
                Reason = reason ?? "Session closed"
            };

            var messageId = Session.SendMessage(header, closeSession);

            if (messageId == header.MessageId)
            {
                Notify(OnCloseSession, header, closeSession);
                Session.OnSessionClosed();
            }

            return(messageId);
        }
 /// <summary>
 /// Handles the CloseSession message from a client.
 /// </summary>
 /// <param name="header">The message header.</param>
 /// <param name="closeSession">The CloseSession message.</param>
 protected virtual void HandleCloseSession(IMessageHeader header, CloseSession closeSession)
 {
     Notify(OnCloseSession, header, closeSession);
     Session.OnSessionClosed();
     Session.Close(closeSession.Reason);
 }