当前位置:网站首页>Websocket implementation principle
Websocket implementation principle
2022-06-30 04:24:00 【No bug program yuan】
websocket Same as http and https equally , Belong to tcp Based on the application layer protocol ; need Three handshakes, four waves The process of
Generally speaking , What we use http The protocol can only be requested by the client , The server cannot push data directly and actively , This leads to continuous changes on the server ( Such as chat rooms ) The client side is more complex to obtain ( Such as real-time performance and service side pressure ). therefore ,websocket The agreement came into being
about websocket Agreement for , Both the client and the server can actively push messages , The message content can be either text or binary data . And there is no restriction of homology policy , There is no cross domain problem
websocket The representation of the agreement ws(ws://xxxx.com); image https equally , If encrypted , The identifier is wxs
websocket Handshake
Handshake : Verify that the server supports websocket agreement
1) Create connection , The browser connects to the server , Connection created successfully
2) The browser generates a random string , The browser saves a copy of the random string , Send a copy to the server at the same time ( be based on http The protocol is sent to the server , Will put the string in http The request header is sent to the server )
3) After the server receives the random string , Let it follow the magic string (magic string, Globally recognized fixed string ) Splicing , And then through sha1 The algorithm encrypts and then passes base64 After the coding , Generating ciphertext
4) The server returns the ciphertext to the browser ( The ciphertext cannot be inversely solved )
5) The browser also matches the locally stored random string with magic string A ciphertext is obtained by splicing and encrypting
6) The browser compares the ciphertext sent by the server with the local ciphertext 、 check , If through , It means that both ends use the same magic string, The same encryption method that is used , That is, it can be determined that the server supports websocket agreement , Shake hands with success ; If the verification fails , It means that the server does not support websocket agreement , Handshake failed
边栏推荐
- Refers to the difference between IP and *ip at output
- Thinkphp5 implements import function
- Indefinite parameters of JS function
- Technology sharing | broadcast function design in integrated dispatching
- Qt 6.3.1Conan软件包发布
- iMile 利用 Zadig 多云环境周部署千次,跨云跨地域持续交付全球业务
- Find the interface and add parameters to the form
- Concatenation of Languages(UVA10887)
- Five methods to clear floating and their advantages and disadvantages
- With the deep integration of cloud platform, the "Xueba" objectscale in the object storage industry is coming
猜你喜欢

Redis cache avalanche, breakdown and penetration

Day 10 data saving and loading
![[Thesis reading | deep reading] dane:deep attributed network embedding](/img/c7/60f36c2748b8cd7544b7ef14dc309e.png)
[Thesis reading | deep reading] dane:deep attributed network embedding

Explain the underlying principles of JVM garbage collection in simple terms

Machine learning notes

How the FortiGate firewall rejects a port by using the local in policy policy

Junior students summarize JS basic interview questions

How to use div boxes to simulate line triangles

Myrpc version 0

Imile uses Zadig's multi cloud environment to deploy thousands of times a week to continuously deliver global business across clouds and regions
随机推荐
Error encountered in SQL statement, solve
数据链路层详解
El upload Upload file (Manual upload, Automatic upload, upload progress)
Indefinite parameters of JS function
487-3279(POJ1002)
AI落地的新范式,就“藏”在下一场软件基础设施的重大升级里
Find the interface and add parameters to the form
thinkphp5实现导入功能
The new paradigm of AI landing is "hidden" in the next major upgrade of software infrastructure
How to solve the problem of link hyperlinks when trying to link the database?
mysql更新数组形式的json串
Implementation steps of dynamic proxy
SQL追加字段
Robot slam navigation core technology and practice Season 1: Chapter 0_ Slam development overview
JS generator
Myrpc version 2
El upload upload file (manual upload, automatic upload, upload progress)
SQL server2005中SUM函数中条件筛选(IF)语法报错
Anonymous pipeline for interprocess communication
internship:接口案例实现