Esempio n. 1
0
        /// <summary>
        /// 回复握手请求
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="secValue">Sec-WebSocket-Key</param>
        private void ResponseHandshake(IContenxt context, string secValue)
        {
            var wrapper           = new WebSocketSession(context.Session);
            var hansshakeResponse = new HandshakeResponse(secValue);

            if (wrapper.TrySend(hansshakeResponse) == true)
            {
                this.OnSetProtocolWrapper(context.Session, wrapper);
            }
        }
        /// <summary>
        /// 回复握手请求
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="secValue">Sec-WebSocket-Key</param>
        /// <returns></returns>
        private Task ResponseHandshake(IContenxt context, string secValue)
        {
            return(new Task(() =>
            {
                try
                {
                    var wrapper = new WebSocketSession(context.Session);
                    var hansshakeResponse = new HandshakeResponse(secValue);

                    wrapper.SendAsync(hansshakeResponse);
                    this.OnSetProtocolWrapper(context.Session, wrapper);
                }
                catch (Exception) { }
            }));
        }
Esempio n. 3
0
        /// <summary>
        /// 处理握手
        /// </summary>
        /// <param name="session">会话对象</param>
        /// <param name="buffer">接收到的数据</param>
        private void ProcessHandshake(T session, ReceiveBuffer buffer)
        {
            var request = HttpRequest.From(buffer);

            if (this.OnHandshake(session, request) == false)
            {
                session.Close();
                return;
            }

            // 握手成功
            try
            {
                var response = new HandshakeResponse(request);
                session.SendResponse(response);
            }
            finally
            {
                session.TagData.Set("HANDSHAKED", true);
            }
        }
        /// <summary>
        /// 处理握手
        /// </summary>
        /// <param name="session">会话对象</param>
        /// <param name="buffer">接收到的数据</param>
        private void ProcessHandshake(T session, ReceiveBuffer buffer)
        {
            var request = default(HttpRequest);

            try
            {
                request = HttpRequest.Parse(buffer, this.LocalEndPoint, session.RemoteEndPoint);
            }
            catch (Exception)
            {
                session.Close();
                return;
            }

            // http请求的数据未完整
            if (request == null)
            {
                return;
            }

            if (this.OnHandshake(session, request) == false)
            {
                session.Close();
                return;
            }

            // 握手成功
            try
            {
                var response = new HandshakeResponse(request);
                session.SendResponse(response);
            }
            catch (Exception)
            {
            }
            finally
            {
                session.TagData.Set("HANDSHAKED", true);
            }
        }
        /// <summary>
        /// 回复握手请求
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="secValue">Sec-WebSocket-Key</param>
        /// <returns></returns>
        private Task ResponseHandshake(IContenxt context, string secValue)
        {
            return new Task(() =>
            {
                try
                {
                    var wrapper = new WebSocketSession(context.Session);
                    var hansshakeResponse = new HandshakeResponse(secValue);

                    wrapper.Send(hansshakeResponse);
                    this.OnSetProtocolWrapper(context.Session, wrapper);
                }
                catch (Exception) { }
            });
        }