本文整理汇总了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);
}
示例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);
}
示例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);
}
示例4: ClientReceiveCallback
private void ClientReceiveCallback(ITcpConnection tcpConnection, IEnumerable<ArraySegment<byte>> arraySegments)
{
tcpConnection.ReceiveAsync(ClientReceiveCallback);
ReceiveAndSend(tcpConnection, arraySegments);
}
示例5: OnRawDataReceived
private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data)
{
_framer.UnFrameData(data);
connection.ReceiveAsync(OnRawDataReceived);
}
示例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);
}
示例7: ReconnectToServer
public void ReconnectToServer()
{
_connection.ConnectionClosed -= OnConnectionClosed;
_connection = new TcpClientConnector().ConnectTo(Guid.NewGuid(), _localEndPoint, _serverEndPoint, OnConnectionEstablished, OnConnectionFailed);
_connection.ConnectionClosed += OnConnectionClosed;
_connection.ReceiveAsync(OnRawDataReceived);
}
示例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);
}
示例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);
}
示例10: OnDataReceived
private void OnDataReceived(ITcpConnection conn, IEnumerable<ArraySegment<byte>> data)
{
conn.EnqueueSend(data);
conn.ReceiveAsync(OnDataReceived);
}
示例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);
}