Socket.io – easy way to handle WebSockets
Content Source: Python
Web Development
The era of static websites has passed. Now users demand
dynamic content and application like look and feel. Instead of constantly
reloading the page and hitting F5, the page should adjust itself automatically.
Many of this can be accomplished with simple asynchronous requests from
javascript. But what if you want to update your app only when there is a new
data available on the server?
You could send a ton of requests in a loop but that’ll use a
lot of bandwidth and with more users could potentially DDoS your server or make
it very slow. Web
technologies are constantly evolving so it’s not exceptional that we have a
solution for this problem. It’s called WebSockets.
Websockets allows us to establish a stateful connection
between browser and server so we can exchange pieces of information in both
directions. It’s more efficient than standard request and response cycle from
HTTP.
Unfortunately, WebSockets are handled differently on
different browsers so it’s not easy to implement the cross-browser code. And
how about older browsers that don’t support WebSockets? We need some kind of
wrapper that will work on different browsers and fallback to polling techniques
on older ones. Socket.io does exactly that and also provides nice API and many
additional features like broadcasting. Read more…..
Comments
Post a Comment