当前位置:网站首页>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
边栏推荐
- 洛谷P6822 [PA2012]Tax(最短路+边变点)
- 【补题】2021牛客暑期多校训练营4-n
- Looking for b-end product manager after years? I almost ruined myself
- 电子学:第014课——实验 15:防入侵报警器(第一部分)
- Apache CouchDB Code Execution Vulnerability (cve-2022-24706) batch POC
- Cloud computing exam version 1 0
- 【莫比乌斯反演】
- 將數據導入到MATLAB
- 深度学习系列48:DeepFaker
- Dietary intervention reduces cancer treatment-related symptoms and toxicity
猜你喜欢

Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus

TCP 加速小记

Sword finger offer (medium level)

企业全面云化的时代——云数据库的未来

唐老师讲运算放大器(第七讲)——运放的应用

Deep learning series 48:deepfaker

Anaconda navigator启动慢的一个解决方法

Opencv daily function structure analysis and shape descriptor (8) Fitline function fitting line

Electronics: Lesson 012 - Experiment 11: light and sound

FM signal, modulated signal and carrier
随机推荐
How do I install the software using the apt get command?
静态网页服务器
FM signal, modulated signal and carrier
剑指offer刷题(中等等级)
Debugging mipi-dsi screen based on stm32mp157
TCP的那点玩意儿
bat启动.NET Core
Ubuntu18下登录mysql 5.7设置root密码
力扣 272. 最接近的二叉搜索树值 II 递归
PH neutralization process modeling
Apache CouchDB Code Execution Vulnerability (cve-2022-24706) batch POC
Opencv minimum filtering (not limited to images)
电子学:第013课——实验 14:可穿戴的脉冲发光体
To understand the difference between Gram-positive and Gram-negative bacteria and the difference in pathogenicity
Can bus working condition and signal quality "physical examination"
Luogu p1073 [noip2009 improvement group] optimal trade (layered diagram + shortest path)
Set the textalign property of the label control in C to control the method of text centering
What is the difference between agreement and service?
Luogu p2048 [noi2010] super Piano (rmq+ priority queue)
现在通过开户经理发的开户链接股票开户安全吗?