What is the internet speed?
Everyone want to download faster and faster, and also upload files even faster. But what does it mean? When you download or upload something, you and a server are communicating in a particular way.Both of you have an internet connection, but in most cases, your is slower than the server's connection. To understand this, simply follow this logic:
You are playing some video games with other thousands of user. Your (and the other player connection) can send and receive 20 units per second. The server can send up to 2 millions unit per second. In this way everyone is happy and is online. If the server could just send 20 units per second, everyone would've lagged, or even worst (Like package loss).
So, to answer what internet speed is, is the time that takes from a request sent to you, to travel to the server, have a response, and then turn it back to you. Of course if the server is down or has finished his units space to dedicate to you, your request would be delayed, but this is how the internet works.
When you download or stream a film, it happens the same thing: You are requesting new chunk every time you finished to download/stream a small part.
Let's talk about some number
Time is counted, in the internet, in milliseconds. If you just open a terminal and do a simple ping www.stackoverflow.com
you will have something like that :
Reply from 151.101.1.69: bytes=32 time=36ms TTL=56
Reply from 151.101.1.69: bytes=32 time=36ms TTL=56
Reply from 151.101.1.69: bytes=32 time=36ms TTL=56
Reply from 151.101.1.69: bytes=32 time=36ms TTL=56
that time=36ms
is the time passed between you sending the ping request, and the request backing to you.
In the end
I hope to have cleared everything, measuring time, in the web, is intended like this way:
- Start counting
- Send a request
- ...
- Wait..
- ...
- Request turned back
- Stop Counting
** But my question is: Can I do it in angular?**
The answer is.. Kinda. Probably there are better ways to do that, but few months ago I wanted to do it as well, and I came up with that idea.
Let's assume we have a service that do a request :
export class MyService{
constructor(
private http: Http
)
public sendRequest(){
return this.http.get(...something);
}
}
Our main component will have the service injection and will count the times passed :
export class MyComponent{
public timePassed: any;
constructor(
private service: MyService
)
ngOnInit(): void{
const startingTime = new Date().getTime();
this.service.sendRequest()
.subscribe( res => {
this.timePassed = ((new Date() - startingTime).getTime())/1000;
});
}
}
Now in your timePassed
variable you will have the time that the request took.
As I said, the time can change due to your connection being slow, or because the server's connection is slow.
You always have to think at internet speed like two people talking to each other. Always.
It makes no sense otherwise to talk to speed if you can't relate yours to someone else speed.