Exemplo n.º 1
0
        protected override int ProcessHeadersAndUpgrade(NetContext context, Connection connection, Stream input, Stream additionalData, int additionalOffset)
        {
            string requestLine;
            var    headers = ParseHeaders(input, out requestLine);

            if (!string.Equals(headers["Upgrade"], "WebSocket", StringComparison.InvariantCultureIgnoreCase) ||
                !string.Equals(headers["Connection"], "Upgrade", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new InvalidOperationException();
            }

            lock (this)
            {
                var protocol = new WebSocketsProcessor_Hixie76_00.Client(expectedSecurityResponse);
                expectedSecurityResponse = null; // use once only
                connection.SetProtocol(protocol);
                if (pending != null)
                {
                    while (pending.Count != 0)
                    {
                        connection.Send(context, pending.Dequeue());
                    }
                }
            }
            return(0);
        }
Exemplo n.º 2
0
 protected override int ProcessHeadersAndUpgrade(NetContext context, Connection connection, Stream input, Stream additionalData, int additionalOffset)
 {
     string requestLine;
     var headers = ParseHeaders(input, out requestLine);
     if (!string.Equals(headers["Upgrade"], "WebSocket", StringComparison.InvariantCultureIgnoreCase)
         || !string.Equals(headers["Connection"], "Upgrade", StringComparison.InvariantCultureIgnoreCase))
     {
         throw new InvalidOperationException();
     }
     
     lock (this)
     {
         var protocol = new WebSocketsProcessor_Hixie76_00.Client(expectedSecurityResponse);
         expectedSecurityResponse = null; // use once only
         connection.SetProtocol(protocol);
         if (pending != null)
         {
             while (pending.Count != 0)
             {
                 connection.Send(context, pending.Dequeue());
             }
         }
     }
     return 0;
 }