Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3667770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:02:32+00:00 2026-05-19T02:02:32+00:00

I am sending a huge file over TCP using C#, and would like to

  • 0

I am sending a huge file over TCP using C#, and would like to measure the download speed.
How can I capture the transfer rate every second? If I use IPv4InterfaceStatistics or a similar method, I capture the device transfer rate instead of capturing the file transfer rate.
The problem with capturing device transfer rate is that it captures all data passing through the network device instead of the single file that I transfer.

How can I capture the file transfer rate?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:02:33+00:00Added an answer on May 19, 2026 at 2:02 am

    Since you don’t have control over the stream to tell how much is read, you can create timestamps before and after a stream read and then calculate the speed based on the number of received or sent bytes:

    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
    

    You should put the Stream.Read in a try/catch block and handle exceptions that could occur. It’s the same for writing to streams and calculating the speed, only these two lines are affected:

    myStream.Write(buffer, 0, buffer.Length);
    int speed = (buffer.Length * 8) / stopwatch.ElapsedMilliseconds; // kbps
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im sending over some json data and assigning to a hidden field using: @Html.Hidden(hidden-places,
Sending a message from the Unix command line using mail TO_ADDR results in an
When sending data over HTTPS, I know the content is encrypted, however I hear
I'm sending mail from my C# Application, using the SmtpClient. Works great, but I
How can I test sending email from my application without flooding my inbox? Is
I am sending a filename(string), filesize(int), and the file(byte[]). What is happening is that
Sending example.java Transmitting file data .svn: Commit failed (details follow): svn: 'pre-commit' hook failed
Sending a file/key to Amazon S3 via a html form and HTTP Post is
Im sending and receiving posts with ajax and php, now when would be the
I am sending emails using PHP Pear class, when I see mails in gmail,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.