Commit 5d1bf032 authored by zhangfangli's avatar zhangfangli

websocket

parent 29b5c9ab
Pipeline #16585 failed with stage
......@@ -34,8 +34,7 @@ author: 张芳利
## 三、WebSocket特点
- 最大特点就是,服务器可以主动向客户端推送信息,客户端也可以主动向服务器发送信息,是真正的双向平等对话,属于服务器推送技术的一种。
![image.png](https://cdn.nlark.com/yuque/0/2021/png/22328960/1636711322013-09ef7bd7-f732-4195-840c-83fcbdcfc248.png#clientId=u73f4536e-0f71-4&from=paste&height=428&id=uda8cb238&margin=%5Bobject%20Object%5D&name=image.png&originHeight=428&originWidth=526&originalType=binary&ratio=1&size=63554&status=done&style=none&taskId=u4874871e-60bf-492c-87a3-4baa20ad6c6&width=526)
![websocket](/yifu-study-front-share/images/websocket/WebSocket1.png)
- 建立在 TCP 协议之上,服务器端的实现比较容易。
- 与 HTTP 协议有着良好的兼容性。默认端口也是80和443,并且握手阶段采用 HTTP 协议,因此握手时不容易屏蔽,能通过各种 HTTP 代理服务器。
......@@ -45,8 +44,7 @@ author: 张芳利
- 协议标识符是ws(如果加密,则为wss),服务器网址就是 URL。
<a name="b15a1ba5"></a>
## ![image (2).png](https://cdn.nlark.com/yuque/0/2021/png/22328960/1636711353419-ab381e4d-8184-4922-8124-1f2d5413c719.png#clientId=u73f4536e-0f71-4&from=paste&height=312&id=u9624ffb4&margin=%5Bobject%20Object%5D&name=image%20%282%29.png&originHeight=312&originWidth=418&originalType=binary&ratio=1&size=98792&status=done&style=none&taskId=u68c59bb0-8f55-4ea3-8e63-42d7891d833&width=418)
![websocket](/yifu-study-front-share/images/websocket/WebSocket2.png)
<a name="367b4b6d"></a>
## 四、WebSocket的API
......@@ -106,12 +104,11 @@ ws.onmessage = function(evt) {
4、WebSocket和Http协议一样都属于应用层的协议,那么他们之间有没有什么关系呢?答案是肯定的,WebSocket在建立握手连接时,数据是通过http协议传输的,但是在建立连接之后,真正的数据传输阶段是不需要http协议参与的
![image (3).png](https://cdn.nlark.com/yuque/0/2021/png/22328960/1636711400876-41c6837d-6910-48f7-920b-895c2a9c57c4.png#clientId=u73f4536e-0f71-4&from=paste&height=231&id=u56457dac&margin=%5Bobject%20Object%5D&name=image%20%283%29.png&originHeight=231&originWidth=540&originalType=binary&ratio=1&size=13694&status=done&style=none&taskId=u2fa8d643-8a2c-4a8e-8833-f637541b8d5&width=540)
![websocket](/yifu-study-front-share/images/websocket/WebSocket3.png)
<a name="14106cbc"></a>
## 六、WebSocket通讯详细解读
![image (4).png](https://cdn.nlark.com/yuque/0/2021/png/22328960/1636711417314-0d2f463f-929f-4024-ab1b-6a16eb1f51e8.png#clientId=u73f4536e-0f71-4&from=paste&height=506&id=u9dcdacf6&margin=%5Bobject%20Object%5D&name=image%20%284%29.png&originHeight=506&originWidth=531&originalType=binary&ratio=1&size=74952&status=done&style=none&taskId=ue61af358-9ee9-481d-af16-a97863d1fd4&width=531)
![websocket](/yifu-study-front-share/images/websocket/WebSocket4.png)
从图可以明显的看到,分三个阶段:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment