private void RunServer() { Socket listener = Build.TcpIPv4(); listener.Bind(_endpoint); listener.Listen(10); var server = new AsyncNetworkStream(listener.Accept()); var buffer = new byte[1024]; server.Read(buffer, 0, msgSize); Stopwatch watch = Stopwatch.StartNew(); for (var i = 0; i < msgCount; i++) { if (server.Read(buffer, 0, msgSize) != msgSize) { throw new InvalidOperationException(); } } watch.Stop(); var speed = msgCount * 1000.0 / watch.ElapsedMilliseconds; Console.WriteLine($"Receive speed {speed:N3} msg/sec"); }
private void StartListener() { var server = new AsyncNetworkStream(_listener.Accept()); HandshakeMessage handshake = server.ReceiveHandshake().Result; server.SendHandshake(HubId.Generate()); using (var buffer = new PooledMemoryStream()) { while (true) { buffer.Reset(); Receive(server, buffer, WireHeader.Size); buffer.Position = 0; WireHeader header = WireHeader.ReadFrom(buffer); //Console.WriteLine($"Received {header.MessageHeader} ({header.PayloadSize.Value.ToString(CultureInfo.InvariantCulture)})"); Receive(server, buffer, header.PayloadSize.Value); _serverReceived++; if (_serverReceived == _count + 1) { _allMessagesReceived.Set(); } } } }
private void RunClient() { Socket client = Build.TcpIPv4(); client.Connect(_endpoint); var stream = new AsyncNetworkStream(client); byte[] buffer = Enumerable.Range(1, 64).Select(x => (byte)x).ToArray(); stream.Write(buffer, 0, msgSize); Stopwatch watch = Stopwatch.StartNew(); for (var i = 0; i < msgCount; i++) { stream.Write(buffer, 0, msgSize); } watch.Stop(); var speed = msgCount * 1000.0 / watch.ElapsedMilliseconds; Console.WriteLine($"Send speed {speed:N3} msg/sec"); }