当前位置:网站首页>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
边栏推荐
猜你喜欢

Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC

Can transparent cloud gateway caniot and candtu record can messages and send and receive can data remotely

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

c#磁盘驱动器及文件夹还有文件类的操作

双周投融报:资本埋伏Web3基础设施

Stm32cubemx Learning (5) Input capture Experiment

c#ColorDialog更改文本颜色和FontDialog更改文本字体的使用示例

电子学:第011课——实验 10:晶体管开关

使用pytorch搭建MobileNetV2并基于迁移学习训练

什么是SKU和SPU,SKU,SPU的区别是什么
随机推荐
洛谷P2486 [SDOI2011]染色(树链+线段树 + 树上区间合并 )
什么是SKU和SPU,SKU,SPU的区别是什么
Sword finger offer II 027 Palindrome linked list
协议和服务的区别?
Three Siemens fire-fighting hosts fc18 are equipped with can optical transceiver for optical fiber redundant ring network networking test
Is it safe to open an account through the haircut account opening link now?
FM信号、调制信号和载波
数论模板啊
Deep learning series 48:deepfaker
网络模型——OSI模型与TCP/IP模型
Logu P2486 [sdoi2011] coloring (tree chain + segment tree + merging of intervals on the tree)
Luogu p1073 [noip2009 improvement group] optimal trade (layered diagram + shortest path)
DNS协议及其DNS完整的查询过程
TCP stuff
Apache CouchDB Code Execution Vulnerability (cve-2022-24706) batch POC
想转行学软件测试担心哪些问题?
PH neutralization process modeling
Electronics: Lesson 011 - experiment 10: transistor switches
Introduction to the main functions of the can & canfd comprehensive test and analysis software lkmaster of the new usbcan card can analyzer
TCP与UDP