Jump to content

Program for testing upload speed

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
i've write a program for testing download speed but i don't have any idea how to write program for uploading...

here is the code for download speed testing:


using System;

using System.Collections.Generic;

using System.Text;

using System.Net;


namespace TestBrzine

{

   

    class Program

    {

        

        static void Main(string[] args)

        {

            Console.Title = "Ovaj program provjerava brzinu download-a\nAutor: Antonio Halužan";


            // the URL to download a file from

            Uri URL = new Uri("http://sixhoej.net/speedtest/1024kb.txt");

            WebClient wc = new WebClient();


            Console.WriteLine("Pritisnite bilo koju tipku za početak.");

            Console.ReadKey();


            Console.WriteLine("\nDownloading : 1024kb.txt...");

            Console.WriteLine("From http://sixhoej.net/speedtest/");

            Console.WriteLine("Bilješka: Ovaj file će automatski biti izbrisan nakon testa.");

            

            // get current tickcount 

            double starttime = Environment.TickCount;


            // download file from the specified URL, and save it to C:\speedtest.txt

            wc.DownloadFile(URL, @"C:\speedtest.txt");


            // get current tickcount

            double endtime = Environment.TickCount;


            // how many seconds did it take?

            // we are calculating this by subtracting starttime from endtime

            // and dividing by 1000 (since the tickcount is in miliseconds.. 1000 ms = 1 sec)

            double secs = Math.Floor(endtime - starttime) / 1000;


            // round the number of secs and remove the decimal point

            double secs2 = Math.Round(secs, 0);


            // calculate download rate in kb per sec.

            // this is done by dividing 1024 by the number of seconds it

            // took to download the file (1024 bytes = 1 kilobyte)

            double kbsec = Math.Round(1024 / secs);


            Console.WriteLine("\nZavršeno. Statistika:\n");


            Console.WriteLine("1mb download: \t{0} secs ({1} secs)", secs2, secs);

            Console.WriteLine("Download rate: \t{0} kb/sec", kbsec);


            Console.WriteLine("\nPritisnite bilo koju tipku za izlaz...");

            Console.Read();

            Console.WriteLine("Brisanje skinute datoteke)");

            try

            {

                // delete downloaded file

                System.IO.File.Delete(@"C:\speedtest.txt");

                Console.WriteLine("Završeno.");

            }

            catch

            {

                Console.WriteLine("Nije moguće izbrisati datoteku.");

                Console.ReadKey();

            } 

        }


    }

}




#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
You will need to have a server somewhere with a public IP that accepts uploads (FTP, or something similar) so you can upload to it.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
i made it...it was very easy...i found uploadfile method and implement it inside my code for download ;)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users