本文整理汇总了C#中IDataWriter.Log方法的典型用法代码示例。如果您正苦于以下问题:C# IDataWriter.Log方法的具体用法?C# IDataWriter.Log怎么用?C# IDataWriter.Log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataWriter
的用法示例。
在下文中一共展示了IDataWriter.Log方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoAcceptTcpClientCallback
// Process the client connection.
private static void DoAcceptTcpClientCallback(IAsyncResult ar, IDataWriter writer, IDataGetter reader, CancellationToken ct)
{
if (ct.IsCancellationRequested)
return;
// Get the listener that handles the client request.
var listener = (TcpListener)ar.AsyncState;
// End the operation
var client = listener.EndAcceptTcpClient(ar);
client.ReceiveTimeout = TimingConstants.ClientCommunicationTimeout;
client.SendTimeout = TimingConstants.ClientCommunicationTimeout;
writer.Log(new LogItem("New client is coming!", ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString()));
try
{
var currentClient = new ClientThread(client, writer, reader);
//
Task.Run(() => currentClient.Execute(ct), ct);
}
catch (Exception e)
{
writer.Log(new LogItem("Server got an exception when client arrived: " + e.Message, "no ip"));
}
// Signal the calling thread to continue.
_tcpClientConnected.Set();
}
示例2: DoAcceptConnections
public static void DoAcceptConnections(int port, IDataWriter writer, IDataGetter reader, CancellationToken ct)
{
writer.Log(new LogItem("Server is starting now", "no ip"));
var listener = new TcpListener(IPAddress.Any, port);
_tcpClientConnected = new ManualResetEvent(false);
try
{
listener.Start();
writer.Log(new LogItem("Server is started and begin to listen", "All IP"));
var connected = true;
while (!ct.IsCancellationRequested)
{
if (connected)
{
_tcpClientConnected.Reset();
listener.BeginAcceptTcpClient(
ar => DoAcceptTcpClientCallback(ar, writer, reader, ct),
listener);
}
connected = _tcpClientConnected.WaitOne(TimingConstants.DefaultWaitTime);
}
}
catch (SocketException e)
{
writer.Log(new LogItem("Server got an socket error: " + e.Message, "no ip"));
}
finally
{
listener.Stop();
writer.Log(new LogItem("Server is terminated", "no ip"));
}
}