private static void StreamReceived(object sender, StreamReceivedEventArgs args) { try { Console.Write("Stream from " + args.IpPort + " [" + args.ContentLength + " bytes]: "); int bytesRead = 0; int bufferSize = 65536; byte[] buffer = new byte[bufferSize]; long bytesRemaining = args.ContentLength; if (args.DataStream != null && args.DataStream.CanRead) { while (bytesRemaining > 0) { bytesRead = args.DataStream.Read(buffer, 0, buffer.Length); Console.WriteLine("Read " + bytesRead); if (bytesRead > 0) { byte[] consoleBuffer = new byte[bytesRead]; Buffer.BlockCopy(buffer, 0, consoleBuffer, 0, bytesRead); Console.Write(Encoding.UTF8.GetString(consoleBuffer)); } bytesRemaining -= bytesRead; } Console.WriteLine(""); } else { Console.WriteLine("[null]"); } if (args.Metadata != null && args.Metadata.Count > 0) { Console.WriteLine("Metadata:"); foreach (KeyValuePair <object, object> curr in args.Metadata) { Console.WriteLine(" " + curr.Key.ToString() + ": " + curr.Value.ToString()); } } } catch (Exception e) { LogException("StreamReceived", e); } }
private static void ClientStreamReceived(object sender, StreamReceivedEventArgs args) { try { string md5 = BytesToHex(Md5(args.Data)); if (!md5.Equals(_DataLargeMd5) && !md5.Equals(_DataSmallMd5)) { Interlocked.Increment(ref _Failure); Console.WriteLine("[client] [stream] [async] Data MD5 validation failed"); } else { Interlocked.Increment(ref _Success); // Console.WriteLine("[client] [stream] [async] Data MD5 validation success: " + md5); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private static void ServerStreamReceived(object sender, StreamReceivedEventArgs args) { // Console.WriteLine("[server] stream from " + args.IpPort + ": " + BytesToHex(Md5(args.Data)) + " (" + args.Data.Length + " bytes)"); try { string md5 = BytesToHex(Md5(args.Data)); if (!md5.Equals(_DataLargeMd5) && !md5.Equals(_DataSmallMd5)) { Interlocked.Increment(ref _Failure); Console.WriteLine("[server] [stream] [async] Data MD5 validation failed"); } else { Interlocked.Increment(ref _Success); // Console.WriteLine("[server] [stream] [async] Data MD5 validation success: " + md5); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
static void StreamReceived(object sender, StreamReceivedEventArgs args) { Console.Write("Client received " + args.ContentLength + " bytes from " + args.IpPort + ": MD5 " + Md5(args.DataStream)); }