, 당신은 타임 스탬프를하기 전에 읽고 다음 수신 또는 전송 된 바이트에 따라 스트림 후 속도를 계산 :
using System.IO;
using System.Net;
using System.Diagnostics;
// some code here...
StopWatch stopWatch = new stopWatch();
// Begining of the loop
int offset = 0;
stopWatch.Reset();
stopWatch.Start();
bytes[] buffer = new bytes[1024]; // 1 KB buffer
int actualReadBytes = myStream.Read(buffer, offset, buffer.Length);
// Now we have read 'actualReadBytes' bytes
// in 'stopWath.ElapsedMilliseconds' milliseconds.
stopWatch.Stop();
offset += actualReadBytes;
int speed = (actualReadBytes * 8)/stopWatch.ElapsedMilliseconds; // kbps
// End of the loop
을 Stream.Read
을 try/catch
에 넣고 읽기 예외를 처리해야합니다. 그것은 스트림에 기록 동일합니다 및 속도, 단지이 두 줄이 영향을 계산 :이 시간에 의해 당신이있어 얼마나 많은 데이터를 매초마다 확인, 데이터를 수신하는 방법에있어서
myStream.Write(buffer, 0, buffer.Length);
int speed = (buffer.Length * 8)/stopWatch.ElapsedMilliseconds; // kbps
을 나눈다 통과했다. 아니면 여기서 어려움을 겪었나요? –
글쎄, 얼마나 많은 데이터를 성공적으로 C#에서받은 얼마나 매초마다 확인할 수 있습니까? 어쩌면 나는 뭔가를 놓친다. 네트워크 스트림에서 관련 방법을 찾을 수 없습니다. 감사. –