コード例 #1
0
        /// <summary>
        /// Called when a message from a client is received.
        /// </summary>
        /// <param name="e">Metadata and the message from client</param>
        protected override void OnMessage(MessageEventArgs e)
        {
            if (_session == null)
            {
                byte[] clientPublicKey = null;

                var messageEncryptionCookie = Context.CookieCollection["MessageEncryption"];

                if (messageEncryptionCookie?.Value == "1")
                {
                    var shakeHandsCookie = Context.CookieCollection["ShakeHands"];

                    clientPublicKey =
                        Convert.FromBase64String(
                            shakeHandsCookie.Value);
                }

                _session =
                    _server.SessionRepository.CreateSession(
                        clientPublicKey,
                        _server,
                        this);

                _session.BeforeDispose += BeforeDisposeSession;
            }
            else
            {
                ReceiveMessage?.Invoke(e.RawData);
            }
        }
コード例 #2
0
 /// <summary>
 /// Closes the internal websocket session.
 /// </summary>
 private void BeforeDisposeSession()
 {
     _session = null;
     Sessions.CloseSession(ID);
 }