Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the function of WebSockets technology?

Shulou Source: shulou.com Published: 2022-06-02 01:24:04 10月01日 Update

This article mainly explains the "what is the role of WebSockets technology", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "what is the role of WebSockets technology"!

Notifications are used in most websites, so what technology should be used to implement notifications? There are usually two options, one is polling and the other is WebSockets.

Polling

Polling is simple, which is to visit the server every once in a while (for example, 3 minutes) to see if there is any notification. This function can be easily implemented using js's setinterval and ajax. The implementation is simple, low-cost and risk-free. You don't have to worry about increasing the load on the site. It's perfectly normal for a person who is browsing the site to send a request every three minutes.

WebSockets

WebSockets is a new technology, which can establish long-time connection, real-time response and two-way communication. It is very useful in some situations and is suitable for interactions with low latency, high frequency and large amount of data. However, there are technical risks, such as computer room firewalls or agents that do not pass Updated headers, or close idle long-standing connections.

When to put WebSockets into practice

WebSockets can make web pages dynamic and interactive. However, in many cases, using Ajax in conjunction with HTTP streaming or long polling can provide a simple and effective solution.

For example, news, email, and social feed feeds need to be updated dynamically, but it may be possible to update every few minutes. On the other hand, collaboration, games and financial applications need to be closer to real-time.

Delay alone is not the determining factor. If the volume of messages is relatively small (for example, monitoring network failures), HTTP streaming or polling can provide an effective solution. The combination of low latency, high frequency and high capacity is the best example of using WebSocket.

Also keep in mind that on Internet, uncontrolled agents may prevent WebSocket interactions, either because the Upgrade header is not passed, or because they close connections that have been idle for a long time. This means that using WebSocket for applications inside firewalls is a more direct decision than applications that are open to the public.

Thank you for your reading, the above is the content of "what is the role of WebSockets technology". After the study of this article, I believe you have a deeper understanding of the role of WebSockets technology, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Technology role application program website learning application delay effectiveness content dynamic real-time that is situation solution idle solution firewall frequency risk Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB NVidia MySQL Linux