当前位置:网站首页>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
边栏推荐
- allgero报错:Program has encountered a problem and must exit. The design will be saved as a .SAV file
- Electronics: Lesson 014 - Experiment 15: intrusion alarm (Part I)
- Deep learning series 45: overview of image restoration
- [supplementary question] 2021 Niuke summer multi school training camp 9-N
- 电子学:第013课——实验 14:可穿戴的脉冲发光体
- Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC
- php数组函数大全
- 线程+线程问题记录
- 深度学习系列45:图像恢复综述
- 27. remove elements
猜你喜欢

电子学:第008课——实验 6:非常简单的开关

Looking for b-end product manager after years? I almost ruined myself

TCP 加速小记

电子学:第009课——实验 7:研究继电器
![[deep learning lightweight backbone] 2022 edgevits CVPR](/img/13/139d28621403020e3475a30f6148f8.png)
[deep learning lightweight backbone] 2022 edgevits CVPR

电子学:第014课——实验 15:防入侵报警器(第一部分)

电子学:第010课——实验 9:时间与电容器
![Luogu p1073 [noip2009 improvement group] optimal trade (layered diagram + shortest path)](/img/cb/046fe4b47898fd6db86edc8a267c34.png)
Luogu p1073 [noip2009 improvement group] optimal trade (layered diagram + shortest path)

Sword finger offer (medium level)

剑指offer刷题(中等等级)
随机推荐
六月集训(第25天) —— 树状数组
剑指offer刷题(简单等级)
Deep learning series 45: overview of image restoration
图像超分综述:超长文一网打尽图像超分的前世今生 (附核心代码)
27. remove elements
Allgero reports an error: program has encoded a problem and must exit The design will be saved as a . SAV file
电子学:第009课——实验 7:研究继电器
电子学:第012课——实验 13:烧烤 LED
2021ICPC网络赛第一场
Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
TCP stuff
Neural network and deep learning-3-simple example of machine learning pytorch
Niuke: flight route (layered map + shortest path)
Anaconda navigator启动慢的一个解决方法
Matlab code format one click beautification artifact
Thread + thread problem record
Luogu p2048 [noi2010] super Piano (rmq+ priority queue)
深度学习系列45:图像恢复综述
c#ColorDialog更改文本颜色和FontDialog更改文本字体的使用示例
bat启动.NET Core