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:
(m_cns.GetCurWebTime (m_url.GetBuffer (512)));
If you want to use it, just look at the header of the class.
char * GetCurWebTime(char *url);
char * GetState(int time);
USHORT checksum(USHORT *buffer, int size);
void fill_icmp_data(char* icmp_data,int datasize);
struct sockaddr_in dest,from;
struct hostent * hp;
int fromlen ;
unsigned int addr;
unsigned short iphdrlen;
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