private static async Task RunClientAsync(TcpClient client) { var buffer = new byte[256]; var buf = new ArraySegment <byte>(buffer); while (true) { try { var len = await client.Client.ReceiveAsync(buf, SocketFlags.None); if (len == 0) { client.Dispose(); Statistics.DecrementClient(); break; } Statistics.IncrementReceivedTimes(); var sendBuffer = new ArraySegment <byte>(buffer, 0, len); await client.Client.SendAsync(sendBuffer, SocketFlags.None); Statistics.IncrementSendTimes(); } catch (Exception ex) { //Console.WriteLine($"RunClientAsync Error: {ex}"); client.Dispose(); Statistics.DecrementClient(); break; } } }
private static async Task RunClientAsync(TcpClient client) { var receiveBufferBytes = new byte[256]; var sendBytes = Encoding.UTF8.GetBytes("price ever, and a new, shiny red iPhone 7, whose sales will help to …On the 60th day of his presidency came the hardest truth for Donald Trump. He was wrong. James B. Comey — the FBI director whom Trump celebrated on the …Washington PostTrump"); while (true) { try { var sendBuffer = new ArraySegment <byte>(sendBytes, 0, sendBytes.Length); await client.Client.SendAsync(sendBuffer, SocketFlags.None); Statistics.IncrementSendTimes(); var receiveBuffer = new ArraySegment <byte>(receiveBufferBytes); var len = await client.Client.ReceiveAsync(receiveBuffer, SocketFlags.None); if (len == 0) { client.Dispose(); Statistics.DecrementClient(); break; } Statistics.IncrementReceivedTimes(); await Task.Delay(30 * 1000); } catch (Exception ex) { //Console.WriteLine($"RunClientAsync Error: {ex}"); client.Dispose(); Statistics.DecrementClient(); break; } } }