private void appServer_SessionClosed(WebSocketSession session, CloseReason reason)
        {
            // Stop keepalive message timer
            KeepAliveDMYMsgTimer keepaliveMsgTimer = (KeepAliveDMYMsgTimer)session.Items["KeepAliveTimer"];

            keepaliveMsgTimer.Stop();

            IPAddress destinationAddress = session.RemoteEndPoint.Address;

            logger.Info("Session closed from : " + destinationAddress.ToString() + " Reason :" + reason.ToString());
        }
        /// <summary>
        /// Constructor of KeepAliveMsgTimer
        /// </summary>
        /// <param name="session">Target WebSocket session.</param>
        /// <param name="interval">Keep alive interval in milisecond.</param>
        public KeepAliveDMYMsgTimer(WebSocketSession session, int interval)
        {
            this.webSocketSession  = session;
            this.KeepAliveInterval = interval;

            this.keepAliveTimer = new Timer((object obj) =>
            {
                KeepAliveDMYMsgTimer timerObj  = (KeepAliveDMYMsgTimer)obj;
                WebSocketSession targetSession = timerObj.webSocketSession;

                targetSession.Send(DUMMY_MESSAGE);
            }, this, Timeout.Infinite, KeepAliveInterval);
        }
        private void appServer_NewSessionConnected(WebSocketSession session)
        {
            lock (create_session_busy_lock_obj)//Wait websocket session is created.
            {
                WebsocketSessionParam sendparam         = createSessionParam();
                KeepAliveDMYMsgTimer  keepAliveMsgTimer = new KeepAliveDMYMsgTimer(session, this.KeepAliveInterval);
                keepAliveMsgTimer.Start();

                session.Items.Add("Param", sendparam);
                session.Items.Add("KeepAliveTimer", keepAliveMsgTimer);

                IPAddress destinationAddress = session.RemoteEndPoint.Address;
                logger.Info("New session connected from : " + destinationAddress.ToString());
            }
        }