Skip to content

Commit

Permalink
Update for .NET Standard 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LiveOrDevTrying committed May 30, 2023
1 parent 1c4f8c0 commit 1bc10ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Tcp.NET.Client/Handlers/TcpClientHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ protected virtual async Task ReceiveAsync(CancellationToken cancellationToken)
{
if (_connection.TcpClient.Available > 0)
{
var buffer = new ArraySegment<byte>(new byte[_connection.TcpClient.Available]);
var result = await _connection.TcpClient.Client.ReceiveAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
await _connection.MemoryStream.WriteAsync(buffer.Array.AsMemory(buffer.Offset, result), cancellationToken).ConfigureAwait(false);
var buffer = new byte[_connection.TcpClient.Available];
var result = _connection.TcpClient.Client.Receive(buffer);
await _connection.MemoryStream.WriteAsync(buffer, 0, result, cancellationToken).ConfigureAwait(false);

_connection.EndOfLine = Statics.ByteArrayContainsSequence(_connection.MemoryStream.GetBuffer(), _parameters.EndOfLineBytes) > -1;
}
Expand Down Expand Up @@ -277,7 +277,7 @@ protected virtual async Task ReceiveAsync(CancellationToken cancellationToken)

if (bytes.Length > 0)
{
await _connection.MemoryStream.WriteAsync(bytes, cancellationToken);
await _connection.MemoryStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Tcp.NET.Server/Handlers/TcpHandlerServerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ protected virtual async Task ReceiveAsync(Z connection, CancellationToken cancel
{
var buffer = new byte[connection.TcpClient.Available];
var result = connection.TcpClient.Client.Receive(buffer, SocketFlags.None);
await connection.MemoryStream.WriteAsync(buffer.Array.AsMemory(buffer.Offset, result), cancellationToken).ConfigureAwait(false);
await connection.MemoryStream.WriteAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false);

connection.EndOfLine = Statics.ByteArrayContainsSequence(connection.MemoryStream.GetBuffer(), _parameters.EndOfLineBytes) > -1;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ protected virtual async Task ReceiveAsync(Z connection, CancellationToken cancel
}
}

await connection.MemoryStream.WriteAsync(bytes, cancellationToken);
await connection.MemoryStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
}
}
}
Expand All @@ -300,7 +300,7 @@ public override async Task<bool> SendAsync(string message, Z connection, Cancell
if (connection.TcpClient.Connected && connection.TcpClient.Client != null && !cancellationToken.IsCancellationRequested && _isRunning && !string.IsNullOrWhiteSpace(message))
{
var bytes = Statics.ByteArrayAppend(Encoding.UTF8.GetBytes(message), _parameters.EndOfLineBytes);
await connection.TcpClient.Client.SendAsync(new ArraySegment<byte>(bytes), SocketFlags.None, cancellationToken).ConfigureAwait(false);
connection.TcpClient.Client.Send(bytes, 0, bytes.Length, SocketFlags.None, out var error);

FireEvent(this, CreateMessageEventArgs(new TcpMessageServerBaseEventArgs<Z>
{
Expand Down Expand Up @@ -336,7 +336,7 @@ public override async Task<bool> SendAsync(byte[] message, Z connection, Cancell
if (connection.TcpClient.Connected && connection.TcpClient.Client != null && !cancellationToken.IsCancellationRequested && _isRunning && message.Where(x => x != 0).Any())
{
var bytes = Statics.ByteArrayAppend(message, _parameters.EndOfLineBytes);
await connection.TcpClient.Client.SendAsync(new ArraySegment<byte>(bytes), SocketFlags.None, cancellationToken).ConfigureAwait(false);
connection.TcpClient.Client.Send(bytes, 0, bytes.Length, SocketFlags.None, out var error);

FireEvent(this, CreateMessageEventArgs(new TcpMessageServerBaseEventArgs<Z>
{
Expand Down
2 changes: 1 addition & 1 deletion TestApps/Tcp.NET.TestApps.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private static void OnConnectionEvent(object sender, TcpConnectionClientEventArg
break;
case ConnectionEventType.Disconnect:
var client = (ITcpNETClient)sender;
_clients.TryRemove(_clients.FirstOrDefault(x => x.Key == client.GetHashCode()));
_clients.TryRemove(client.GetHashCode(), out var _);

client.ConnectionEvent -= OnConnectionEvent;
client.MessageEvent -= OnMessageEvent;
Expand Down

0 comments on commit 1bc10ab

Please sign in to comment.