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


C# ITcpConnection.ReceiveAsync方法代码示例

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


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

示例1: SocketClient

 public SocketClient()
 {
     var remoteEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), DEFAULT_PORT);
     var connector = new TcpClientConnector();
     _connection = connector.ConnectTo(_connectionId, remoteEndPoint, ConnectionTimeout, OnConnectionEstablished, OnConnectionFailed);
     _connection.ConnectionClosed += OnConnectionClosed;
     _connection.ReceiveAsync(OnRawDataReceived);
 }
开发者ID:Cocotus,项目名称:SocketAsyncSample,代码行数:8,代码来源:SocketClient.cs

示例2: OnRawDataReceived

 private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data)
 {
     try
     {
         _framer.UnFrameData(data);
     }
     catch (PackageFramingException exc)
     {
         Console.WriteLine(exc.Message);
         return;
     }
     connection.ReceiveAsync(OnRawDataReceived);
 }
开发者ID:Cocotus,项目名称:SocketAsyncSample,代码行数:13,代码来源:AcceptedConnection.cs

示例3: OnDataReceived

        private void OnDataReceived(ITcpConnection conn, IEnumerable<ArraySegment<byte>> data)
        {
            IMessageFramer framer;
            Tuple<ITcpConnection, IMessageFramer> pair;
            if (!_clientFramers.TryGetValue(conn.ConnectionId, out pair))
            {
                framer = new CrappyTemporaryFramer();
                framer.RegisterMessageArrivedCallback(CompleteMessageArrived);
                _clientFramers.TryAdd(conn.ConnectionId, new Tuple<ITcpConnection, IMessageFramer>(conn, framer));

                //Note: we stick the connection ID in the first part of the message just so we
                // can find it later. This isn't especially nice and is fixed in real code
                var connectionId = conn.ConnectionId.ToByteArray();
                framer.UnFrameData(new ArraySegment<byte>(connectionId, 0, connectionId.Length));
            }
            else
            {
                framer = pair.Item2;
            }

            framer.UnFrameData(data);
            conn.ReceiveAsync(OnDataReceived);
        }
开发者ID:jen20,项目名称:tcp-servers-talk,代码行数:23,代码来源:BasicEchoServer.cs

示例4: ClientReceiveCallback

 private void ClientReceiveCallback(ITcpConnection tcpConnection, IEnumerable<ArraySegment<byte>> arraySegments)
 {
     tcpConnection.ReceiveAsync(ClientReceiveCallback);
     ReceiveAndSend(tcpConnection, arraySegments);
 }
开发者ID:kpyatkivskyy,项目名称:mono-socket-problem,代码行数:5,代码来源:test_random_bidirectional_transfer.cs

示例5: OnRawDataReceived

 private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data)
 {
     _framer.UnFrameData(data);
     connection.ReceiveAsync(OnRawDataReceived);
 }
开发者ID:bmavity,项目名称:EventStore,代码行数:5,代码来源:TcpTypedConnection.cs

示例6: Start

 public void Start(int connectTimeoutMilliseconds = 5000)
 {
     _connection = new TcpClientConnector().ConnectTo(Guid.NewGuid(), _localEndPoint, _serverEndPoint, OnConnectionEstablished, OnConnectionFailed);
     _connection.ConnectionClosed += OnConnectionClosed;
     _connection.ReceiveAsync(OnRawDataReceived);
     _waitHandle.WaitOne(connectTimeoutMilliseconds);
 }
开发者ID:hong1990,项目名称:ecommon,代码行数:7,代码来源:TcpClient.cs

示例7: ReconnectToServer

 public void ReconnectToServer()
 {
     _connection.ConnectionClosed -= OnConnectionClosed;
     _connection = new TcpClientConnector().ConnectTo(Guid.NewGuid(), _localEndPoint, _serverEndPoint, OnConnectionEstablished, OnConnectionFailed);
     _connection.ConnectionClosed += OnConnectionClosed;
     _connection.ReceiveAsync(OnRawDataReceived);
 }
开发者ID:hong1990,项目名称:ecommon,代码行数:7,代码来源:TcpClient.cs

示例8: OnRawDataReceived

 private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data)
 {
     try
     {
         _framer.UnFrameData(data);
     }
     catch (PackageFramingException ex)
     {
         _logger.Error("UnFrame data has exception.", ex);
         return;
     }
     connection.ReceiveAsync(OnRawDataReceived);
 }
开发者ID:hong1990,项目名称:ecommon,代码行数:13,代码来源:TcpClient.cs

示例9: OnRawDataReceived

        private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data)
        {
            try
            {
                _framer.UnFrameData(data);
            }
            catch (PackageFramingException exc)
            {
                _log.Error(exc, "Invalid TCP frame received.");
                Close("Invalid TCP frame received.");
                return;
            }

            //NOTE: important to be the last statement in the callback
            connection.ReceiveAsync(OnRawDataReceived);
        }
开发者ID:jjvdangelo,项目名称:EventStore,代码行数:16,代码来源:TcpPackageConnection.cs

示例10: OnDataReceived

 private void OnDataReceived(ITcpConnection conn, IEnumerable<ArraySegment<byte>> data)
 {
     conn.EnqueueSend(data);
     conn.ReceiveAsync(OnDataReceived);
 }
开发者ID:jen20,项目名称:tcp-servers-talk,代码行数:5,代码来源:BasicEchoServer.cs

示例11: OnRawDataReceived

        private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data)
        {
            try
            {
                _framer.UnFrameData(data);
            }
            catch (PackageFramingException exc)
            {
                Log.Debug(exc, "Invalid TCP frame received.");
                Close();
                return;
            }

            connection.ReceiveAsync(OnRawDataReceived);
        }
开发者ID:robashton,项目名称:EventStore,代码行数:15,代码来源:TcpTypedConnection.cs


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