Beispiel #1
0
        public void ProcessIncomingRequest(Connection c)
        {
            if (c.HttpReader.HasUpgarde(Upgrades.Websocket))
            {
                // c.HttpReader.SecWebSocketProtocol

                var    key = c.HttpReader.SecWebSocketKey.ToString();
                byte[] accept;
                lock (sha1)
                    accept = sha1.ComputeHash(Encoding.ASCII.GetBytes(key + guid));

                using (var writer = new HttpMessageWriter())
                {
                    writer.WriteStatusLine(StatusCodes.SwitchingProtocols);
                    writer.WriteConnectionUpgrade();
                    writer.WriteUpgradeWebsocket();
                    writer.WriteSecWebSocketAccept(accept);
                    writer.WriteSecWebSocketProtocol(sip);
                    writer.WriteContentLength(0);
                    writer.WriteCRLF();

                    SendResponse(c, writer, InvalidAgentIndex);
                }

                c.UpgradeToWebsocket();
            }
            else
            {
                base.ProcessIncomingRequest(c);
            }
        }