本文整理汇总了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;
}
}
}
}