Click here to Skip to main content
13,259,771 members (48,372 online)
Click here to Skip to main content
Add your own
alternative version


6 bookmarked
Posted 4 Apr 2010

Simple Class Used To Get Current Webpage's Net Speed

, 4 Apr 2010
Rate this:
Please Sign up or sign in to vote.
Really a tiny class, used to get the currently webpage's net speed you are opening


The tiny class is used to help find the current webpage's speed. You can add this function to your own web browser. Many browser users claim to have this function. So I write an easy one. If you have a much better method to do that, please let me know. I will be grateful.


When we open a webpage, we don't want to wait longer to open it, and other pages also have the same content. Now, the class helps you decide whether to change to another.

Using the Code

Add the two files to your project, "CurNetSpeed.cpp" and "CurNetSpeed.h".

Include the header files to where you want to call. And now do as follows:

//Step 1:

#include "CurNetSpeed.h"
//Step 2:
BOOL CTestNetSpeedDemoDlg::OnInitDialog()
	if(!m_cns.Init ())
		AfxMessageBox("Init failed!");
void CTestNetSpeedDemoDlg::OnTest() 
	// TODO: Add your control notification handler code here
		(m_cns.GetCurWebTime (m_url.GetBuffer (512)));

If you want to use it, just look at the header of the class.

class CCurNetSpeed  
	char * GetCurWebTime(char *url);
	BOOL Init();
	virtual ~CCurNetSpeed();
	char * GetState(int time);
	USHORT checksum(USHORT   *buffer, int size);
	void fill_icmp_data(char* icmp_data,int datasize);
	char url[512];
		  WSADATA wsaData;   
	  SOCKET   sockRaw;   
	  struct   sockaddr_in   dest,from;   
	  struct   hostent   *   hp;   
	  int bread,datasize;   
	  int fromlen ;   
	  int timeout;   
	  char   *dest_ip;   
	  char   *icmp_data;   
	  char   *recvbuf;   
	  unsigned   int   addr;   
	  USHORT   seq_no;   

  IpHeader   *iphdr;   
  IcmpHeader   *icmphdr;   
  unsigned   short   iphdrlen;   
  int time;
  int bwrote;

There aren't many public methods, so you can extend it as per your requirements.

Principle of the Code

How to get the speed of the webpage you are opening? I thought much about it, but I haven't found a better method. This class uses the code of "Ping.exe". You want to know how long your computer's packet takes to get to the web server. Just ping the server. The ping command will retrieve icmp message, the icmp message has a time stamp, use the current time minus the time stamp will to give the time elapsed.


  • 5th April, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Aric Wang
China China

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
csharpbd27-Feb-13 8:54
membercsharpbd27-Feb-13 8:54 
GeneralMy vote of 1 Pin
Sheldon Lemoine12-Apr-10 12:44
memberSheldon Lemoine12-Apr-10 12:44 
RantVery basic and not very useful ... Pin
TommyTooth5-Apr-10 22:29
memberTommyTooth5-Apr-10 22:29 
GeneralRe: Very basic and not very useful ... Pin
Aric Green6-Apr-10 0:16
memberAric Green6-Apr-10 0:16 
GeneralRe: Very basic and not very useful ... Pin
AndersChen11-Oct-10 21:35
memberAndersChen11-Oct-10 21:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 5 Apr 2010
Article Copyright 2010 by Aric Wang
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid