あなたはタイムスタンプをすることができますどのくらいの読み取り、ストリーム読み込んで受信または送信されたバイトに基づいて速度を計算する前と後に彼に伝えるために、ストリームを制御できませんので:
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
に置き、読み取り例外を処理する必要があります。これは、ストリームに書き込むために同じだと速度を計算し、ちょうどこの2行が影響を受けます。
myStream.Write(buffer, 0, buffer.Length);
int speed = (buffer.Length * 8)/stopWatch.ElapsedMilliseconds; // kbps
データを受信する方法では、あなたが持っている秒どのくらいのデータのすべてをチェックして、除算あり、時間によって合格。それとも、ここで何か難しかったですか? –
よく、どのくらいのデータをC#で正常に受信したか毎秒確認できますか?多分私は何かが恋しいです。私はネットワークストリームで関連する方法を見つけることができません。ありがとう。 –