示例#1
0
        /// <summary>
        /// 解析连接请求信息
        /// </summary>
        /// <param name="buffer">接收到的原始数量</param>
        /// <returns></returns>
        public static HttpRequest From(ReceiveBuffer buffer)
        {
            buffer.Position = 0;
            var bytes = buffer.ReadArray();

            buffer.Clear();
            return(HttpRequest.From(bytes, "ws"));
        }
示例#2
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);
            }
        }