Now a days it's become a good , useful and necessary technique to view live data. It's look cool when you see any change in your system on front end with in no time. The first technique comes in mind to solve this problem is Polling.
Polling is basically a simple technique to get real time data. In polling you simply call your server or system continuously after a fixed interval of time. Through polling we get real time data with out installing any agent in system, but their is some cons about polling. One of the biggest problem with polling is that it increase over head on server. Due to which it assume that polling is not a good technique to resolve real time data problem. And if there is no change on server or data our program still continuously make request on server.
Some thing we want is to get real time data from server without requesting server. Nothing is impossible in programming. Every problem has a solution in this field. So, their is some more techniques to use to get real time data without polling.
There are 3 solutions to remove polling
To overcome deficiency in polling techniques, developers move to long polling. In long polling client send request to server and server holds the request until their is any change on server about what client requested, in this way we resolve one issue that client not request again and again if their is no change on server. But still it is the same as polling that increase overhead on server.
So the next and one of the best available techniques in server sent events, In SSE server notify the client side that "Hi! there is some change on me". So no need for client to continuously check or call server. But client and server check a keep alive call to check if they connected or not. So it is a better solution to get real time data without polling.
But wait What if need to send some data from client to server like in chat applications? SSE in unidirectional. But their is another solution called Web sockets. Web sockets are bidirectional. They work similar to SSE but also allow client to send data to server. So information send to client from server when their is any change. Web sockets are mainly use in chat applications because their we need bidirectional traffic.
Polling is basically a simple technique to get real time data. In polling you simply call your server or system continuously after a fixed interval of time. Through polling we get real time data with out installing any agent in system, but their is some cons about polling. One of the biggest problem with polling is that it increase over head on server. Due to which it assume that polling is not a good technique to resolve real time data problem. And if there is no change on server or data our program still continuously make request on server.
Some thing we want is to get real time data from server without requesting server. Nothing is impossible in programming. Every problem has a solution in this field. So, their is some more techniques to use to get real time data without polling.
There are 3 solutions to remove polling
- Long polling
- Server sent events
- Web sockets
To overcome deficiency in polling techniques, developers move to long polling. In long polling client send request to server and server holds the request until their is any change on server about what client requested, in this way we resolve one issue that client not request again and again if their is no change on server. But still it is the same as polling that increase overhead on server.
So the next and one of the best available techniques in server sent events, In SSE server notify the client side that "Hi! there is some change on me". So no need for client to continuously check or call server. But client and server check a keep alive call to check if they connected or not. So it is a better solution to get real time data without polling.
But wait What if need to send some data from client to server like in chat applications? SSE in unidirectional. But their is another solution called Web sockets. Web sockets are bidirectional. They work similar to SSE but also allow client to send data to server. So information send to client from server when their is any change. Web sockets are mainly use in chat applications because their we need bidirectional traffic.