The difference between websockets and rotation implementations

Source: Internet
Author: User

If you've ever used a server-side language and a database to build a web chat room, you'll want to know the difference between the websockets and the traditional way of implementation.

Traditional chat rooms are usually implemented using the polling method. The client periodically asks the server if there is an update. The server replies to the client's updated data or is not updated. However, the traditional approach has the following problems. Only the client actively asks the server to obtain the updated data from the server. This means that the updated data is periodically delayed and the server is not responding in a timely manner. If we want to improve this problem by reducing the polling process, we need more bandwidth because the client needs to send requests to the server without interruption.

Shows the request between the client and the server. It indicates that many useless requests have been sent, but there is no new data in the content that the server replies to the client.

Long polling is a better polling method. The client sends a request to the server and waits for a reply. Instead of the traditional polling method, the server replies with "No update" and the server replies only when it needs to push the information to the server. In this approach, the server can push information to the client whenever an update is available. Once the client receives a response from the server, it builds another request and waits for the next server to push. Displays a long poll, the client asks for updates, and the server replies only when there is an update:

In the WebSockets method, the number of requests is significantly less than the polling method. This is because the connection between the client and the server is permanent. Once the connection is established, the client or server side sends the request only when the information is updated. For example, the client sends information to the server when it wants to update the information to the server. The server sends a message to the client only if it needs to be pushed to the client to update the data. In the connection, there is no useless request sent. Therefore, only a smaller bandwidth is required. Shows the WebSockets method:

The difference between websockets and rotation implementations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.