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


C# IDataWriter.Log方法代码示例

本文整理汇总了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();
        }
开发者ID:AndreyRepko,项目名称:BBrother,代码行数:28,代码来源:ServerMainThread.cs

示例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"));
            }
        }
开发者ID:AndreyRepko,项目名称:BBrother,代码行数:37,代码来源:ServerMainThread.cs


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