コード例 #1
0
ファイル: HttpServer.cs プロジェクト: hungdluit/sipserver
		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);
			}
		}