当前位置: 首页>>代码示例>>C#>>正文


C# NetworkStream.ReadRequest方法代码示例

本文整理汇总了C#中NetworkStream.ReadRequest方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkStream.ReadRequest方法的具体用法?C# NetworkStream.ReadRequest怎么用?C# NetworkStream.ReadRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkStream的用法示例。


在下文中一共展示了NetworkStream.ReadRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequest

        private static void ProcessRequest(bool isFcgiDebug, FcgiSynchronizer sync, Socket s)
        {
            using (s)
              using (var stream = new NetworkStream(s))
              {
            Log("accepted..");

            for (var i = 0; i < 20; ++i)
            {
              if (stream.DataAvailable)
            break;
              System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(30));
              if (i == 19)
              {
            Log("cancel");
            return;
              }
            }

            var parameters = new Dictionary<string, string>();
            for (; ; )
            {
              var req = stream.ReadRequest();
              if (isFcgiDebug)
            Log(string.Format("{0}:{1}, {2}:{3}:{4}", req.Version, req.Type, req.RequestId, req.Content.Hex(), req.Padding.Hex()));

              if (req.Type == FcgiType.Params)
              {
            var _parameters = ParseParameters(req.Content);
            if (_parameters.Count > 0)
            {
              parameters = _parameters;
              if (isFcgiDebug)
              {
                Log("parameters:");
                foreach (var pair in parameters)
                  Log(string.Format("  {0}:{1}", pair.Key, pair.Value));
              }
            }
              }
              JsonData json = null;
              if (req.Type == FcgiType.Stdin && req.Content != null && req.Content.Length > 0)
              {
            if (isFcgiDebug)
              Log("Stdin text: " + System.Text.Encoding.UTF8.GetString(req.Content));
            var data = ParseQuery(System.Text.Encoding.UTF8.GetString(req.Content));
            var values = data.ContainsKey("values") ? data["values"] : null;
            if (isFcgiDebug)
              Log("  " + values);
            //var jsSerializer = new System.Net.Json.JsonTextParser();
            var jsSerializer = Newtonsoft.Json.JsonSerializer.Create();
            json = new JsonData(jsSerializer.Deserialize(new Newtonsoft.Json.JsonTextReader(new System.IO.StringReader(values))));

              }
              if (req.Type == FcgiType.Stdin && req.Padding.Length == 0)
              {
            var res_text = string.Format(@"Content-type: text/html

            {0}
            ", sync.ProcessRequest(parameters, json));
            var res_data = System.Text.Encoding.UTF8.GetBytes(res_text);
            var res_pad = new byte[8 - res_data.Length % 8];
            var res = new FcgiRequest { Version = 1, Type = FcgiType.Stdout, RequestId = req.RequestId, Content = res_data, Padding = res_pad };
            stream.Write(res);
            stream.Write(new FcgiRequest { Version = 1, Type = FcgiType.Stdout, RequestId = req.RequestId });
            stream.Write(new FcgiRequest { Version = 1, Type = FcgiType.EndRequest, RequestId = req.RequestId, Content = new byte[8] });
            break;
              }
            }
              }
        }
开发者ID:Serj-Tm,项目名称:SoftTech,代码行数:71,代码来源:FcgiServer.cs


注:本文中的NetworkStream.ReadRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。