本文整理汇总了C#中ISocket.Write方法的典型用法代码示例。如果您正苦于以下问题:C# ISocket.Write方法的具体用法?C# ISocket.Write怎么用?C# ISocket.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISocket
的用法示例。
在下文中一共展示了ISocket.Write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public void Render(ISocket socket, HttpResponseHead head)
{
var status = head.Status;
var headers = head.Headers;
// XXX don't reallocate every time
var sb = new StringBuilder();
sb.AppendFormat("HTTP/1.1 {0}\r\n", status);
if (headers != null)
{
foreach (var pair in headers)
foreach (var line in pair.Value.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
sb.AppendFormat("{0}: {1}\r\n", pair.Key, line);
}
sb.Append("\r\n");
socket.Write(new ArraySegment<byte>(Encoding.ASCII.GetBytes(sb.ToString())), null);
}
示例2: WriteDataSync
void WriteDataSync(ISocket socket)
{
foreach (var d in MakeData())
{
Debug.WriteLine("Client writing data sync.");
socket.Write(new ArraySegment<byte>(d), null);
}
Debug.WriteLine("Client ending connection.");
socket.End();
}
示例3: WriteDataAsync
void WriteDataAsync(ISocket socket, IEnumerator<byte[]> ds)
{
if (ds.MoveNext())
{
Debug.WriteLine("Client writing data async.");
if (!socket.Write(new ArraySegment<byte>(ds.Current), () => WriteDataAsync(socket, ds)))
WriteDataAsync(socket, ds);
}
else
{
Debug.WriteLine("Client ending connection.");
ds.Dispose();
socket.End();
}
}