private void SendFile(RequestSocket client, string path) { var filename = Path.GetFileName(path); client.Send(filename); //var answer = client.ReceiveString(); using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { int rest = (int)fileStream.Length; while (rest >= PartSize) { rest -= PartSize; var part = new byte[PartSize]; fileStream.Read(part, 0, PartSize); client.Send(part, PartSize, false, true); } var lastPart = new byte[rest]; fileStream.Read(lastPart, 0, rest); client.Send(lastPart, rest, false, false); } }
private static int Main(string[] args) { if (args.Length != 3) { Console.WriteLine("usage: remote_lat remote_lat <connect-to> <message-size> <roundtrip-count>"); return 1; } string connectTo = args[0]; int messageSize = int.Parse(args[1]); int roundtripCount = int.Parse(args[2]); using (var req = new RequestSocket()) { req.Connect(connectTo); var msg = new Msg(); msg.InitPool(messageSize); var stopWatch = Stopwatch.StartNew(); for (int i = 0; i != roundtripCount; i++) { req.Send(ref msg, more: false); req.Receive(ref msg); if (msg.Size != messageSize) { Console.WriteLine("message of incorrect size received. Received: {0} Expected: {1}", msg.Size, messageSize); return -1; } } stopWatch.Stop(); msg.Close(); double elapsedMicroseconds = stopWatch.ElapsedTicks*1000000L/Stopwatch.Frequency; double latency = elapsedMicroseconds/(roundtripCount*2); Console.WriteLine("message size: {0} [B]", messageSize); Console.WriteLine("roundtrip count: {0}", roundtripCount); Console.WriteLine("average latency: {0:0.000} [µs]", latency); } return 0; }