当前位置:网站首页>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
边栏推荐
- A solution to the problem of "couldn't open file /mnt/repodata/repomd.xml"
- 2021-07-14
- base64.c
- 找到接口在表单里加参数
- If you encounter problems when using spark for the first time, please ask for help
- Machine learning notes
- lego_ Reading and summary of loam code
- [从零开始学习FPGA编程-52]:高阶篇 - 基于IP核的FPGA开发 - IP核使用的基本框架(以锁相环PLL为例)
- Error encountered in SQL statement, solve
- Anonymous pipeline for interprocess communication
猜你喜欢

进程间通信之匿名管道

Troubleshoot abnormal video playback problems in public network deployment based on Haikang ehomedemo tool

Junior students summarize JS basic interview questions

Anonymous pipeline for interprocess communication
![Tea mall system based on SSM framework [project source code + database script + report]](/img/d9/0a46c0da9839a7186bd3a9ae55f0a5.png)
Tea mall system based on SSM framework [project source code + database script + report]

基于servlet+jsp+mysql实现的工资管理系统【源码+数据库】

Huawei cloud native - data development and datafactory

Slam mapping, automatic navigation and obstacle avoidance based on ROS (bingda robot)

SQLyog导入数据库时报错,求帮解决!

Basic knowledge of redis
随机推荐
Anonymous pipeline for interprocess communication
尝试链接数据库时出现链接超时报错,如何解决?
JS reflect
I get n offers in two months. I don't have any difficult interviewers here
Imile uses Zadig's multi cloud environment to deploy thousands of times a week to continuously deliver global business across clouds and regions
Day 12 advanced programming techniques
Myrpc version 2
I spent three years in a big factory outsourcing, which subverted my understanding!
Qt6 QML Book/Qt Quick 3D/Qt Quick 3D
idea灰屏问题
A solution to the problem of "couldn't open file /mnt/repodata/repomd.xml"
487-3279(POJ1002)
base64.c
Cloud native -- websocket of Web real-time communication technology
Node red series (28): communication with Siemens PLC based on OPC UA node
基于ROS的SLAM建图、自动导航、避障(冰达机器人)
el-upload上傳文件(手動上傳,自動上傳,上傳進度)
lego_loam 代码阅读与总结
Use of thread pool
RPC correction based on arcpy API