当前位置:网站首页>Websocket understanding and application scenarios
Websocket understanding and application scenarios
2022-06-25 08:10:00 【Shrek】
List of articles
One 、 Yes WebSocket The understanding of the
WebSocket yes HTML5 A browser is provided to communicate with the server full duplex communication Network technology , Belongs to the application layer protocol . It's based on TCP Transfer protocol , And reuse HTTP The handshake channel . The browser and the server only need to complete a handshake , A persistent connection can be created directly between the two , And two-way data transmission .
WebSocket The emergence of solves the disadvantages of half duplex communication . Its biggest characteristic is : The server can actively push messages to the client , The client can also actively push messages to the server .
WebSocket principle :: Client to WebSocket The server notifies one with all recipients ID Events , The server notifies all active clients immediately after receiving , Only ID In the receiver ID The client in the sequence will handle this event .
WebSocket The characteristics are as follows :
- Support two-way communication , More real time
- You can send text , You can also send binary data ‘’
- Based on the TCP The agreement above , The server-side implementation is relatively easy
- The data format is lighter , Low performance overhead , Communication efficiency
- There is no homology restriction , The client can communicate with any server
- The protocol identifier is ws( If encryption , Then for wss), The web address of the server is URL
- And HTTP The protocol has good compatibility . The default port is also 80 and 443, And the handshake phase is used HTTP agreement , So shaking hands is not easy to block , Through a variety of HTTP proxy server .
Two 、Websocket Is used as follows :
// stay index.html Direct writing WebSocket, Set the port number of the server to 9999
let ws = new WebSocket('ws://localhost:9999');
// Trigger after the client establishes a connection with the server
ws.onopen = function() {
console.log("Connection open.");
ws.send('hello');
};
// Triggered when the server sends a message to the client
ws.onmessage = function(res) {
console.log(res); // Print is MessageEvent object
console.log(res.data); // What is printed is the received message
};
// Trigger after the client and server establish and close
ws.onclose = function(evt) {
console.log("Connection closed.");
};
3、 ... and 、 Application scenarios
be based on websocket Characteristics of factual communication , The existing application scenarios are :
- bullet chat
- Media chat
- Collaborative editing
- Location based applications
- Sports live update
- Stock fund quotation is updated in real time
边栏推荐
- Electronics: Lesson 010 - Experiment 8: relay oscillator
- Anaconda based module installation and precautions
- 【补题】2021牛客暑期多校训练营9-n
- 417-二叉树的层序遍历1(102. 二叉树的层序遍历、107.二叉树的层次遍历 II、199.二叉树的右视图、637.二叉树的层平均值)
- 50. pow (x, n) - fast power
- 【补题】2021牛客暑期多校训练营4-n
- Can bus working condition and signal quality "physical examination"
- [supplementary question] 2021 Niuke summer multi school training camp 4-N
- [supplementary question] 2021 Niuke summer multi school training camp 6-n
- 使用Adobe Acrobat Pro调整PDF页面为统一大小
猜你喜欢
Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
Sword finger offer (medium level)
Drawing of clock dial
Ubuntu18下登录mysql 5.7设置root密码
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
Looking for b-end product manager after years? I almost ruined myself
Import data into Matlab
使用apt-get命令如何安装软件?
c#磁盘驱动器及文件夹还有文件类的操作
静态网页服务器
随机推荐
Electronics: Lesson 010 - Experiment 8: relay oscillator
FM信号、调制信号和载波
現在通過開戶經理發的開戶鏈接股票開戶安全嗎?
网络模型——OSI模型与TCP/IP模型
Bat start NET Core
How to create a new branch with SVN
Determine whether the user is entering a page for the first time
Electronics: Lesson 014 - Experiment 15: intrusion alarm (Part I)
Modeling and fault simulation of aircraft bleed system
六月集训(第25天) —— 树状数组
洛谷P2486 [SDOI2011]染色(树链+线段树 + 树上区间合并 )
2265. number of nodes with statistical value equal to the average value of subtree
[supplementary question] 2021 Niuke summer multi school training camp 1-3
使用Adobe Acrobat Pro调整PDF页面为统一大小
Sword finger offer (medium level)
Three Siemens fire-fighting hosts fc18 are equipped with can optical transceiver for optical fiber redundant ring network networking test
Cloud computing exam version 1 0
数论模板啊
57. insert interval
Allgero reports an error: program has encoded a problem and must exit The design will be saved as a . SAV file