Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the basic principle of WebSocket?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what are the basic principles of WebSocket". In daily operation, I believe many people have doubts about what the basic principles of WebSocket are. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what are the basic principles of WebSocket?" Next, please follow the editor to study!

WebSocket and HTTP

1. The HTTP protocol has not changed for the emergence of WebSocket.

2. WebSocket belongs to the new protocol after HTTP.

3. There is an intersection between the two, but they are also different.

4. WebSocket borrows HTTP protocol to complete part of the handshake.

WebSocket handshake

Focus on the following fields by capturing the Rongyun WebSocket request

The above is to initiate a WebSocekt request to capture packets. First of all, pay attention to the values that are higher than those of HTTP:

/ / tell the server that the WebSocket protocol is initiated, and the service needs to be processed by WebSocket Upgrade: websocketConnection: UpgradeSec-WebSocket-Key: aI0TsvW7jltfmNOF+1eSqg== / / Base64, which is randomly generated by the browser. It is matched with the Sec-WebSocket-Accept of the server response to provide basic protection. For example, malicious connection, or unintentional connection Sec-WebSocket-Version: 13 / / indicates the version of websocket. If the server does not support this version, you need to return a Sec-WebSocket-Versionheader containing the version number supported by the server.

Take a look at Response Headers:

Sec-WebSocket-Accept: OfEosYlCAcvV/jdwbW33VU0B50k= / / Security verification. According to the request of the client, the first Sec-WebSocket-Key calculation (base64 ($Sec-WebSocket-Accept,'258EAFA5-E914-47DAMI 95CAMI C5AB0DC85B11')) / / informs the client that it has successfully upgraded to the alternative of WebSocketUpgrade: websocketConnection: Upgrade.

There is no perfect alternative to WebSocket for browsers. Can only be simulated with ajax polling or long rotation training (long poll), both of which have performance problems and consume resources

At this point, the study of "what are the basic principles of WebSocket" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report