Comments (1)
Socket
Socket 是一个通信链的句柄,可以用来实现不同虚拟机或不同计算机之间的通信,也可以实现相同主机内的不同进程之间的通讯。
Socket = IP 地址 + 端口 + 协议
IP 地址 + 端口 + 协议 组成一个唯一标识,用来标识一个通信链路。
Socket 其实是对 TCP/IP 进行了高度封装,屏蔽了很多网络细节。这样可以使开发者更好地进行网络编程。其实就是我们写个高度封装内部细节的函数,通过传参来完成指定的行为。
可以这么说,所有的 TCP/UDP 等编程,基本都是按照 Socket 协议标准来进行编程的,换句话说,Socket 是一套标准,就好比 DOM ,所有语言都可以按照 DOM 的接口标准来实现自己的逻辑。
Socket 有自己的原语,开发者可以按照 Socket 的原语在不同语言下的实现方式来进行网络编程。
Web Socket
Websocket只是协议而已
一、WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系,但HTTP是不支持持久连接的(长连接,循环连接的不算)
二丶Websocket是一个持久化的协议
HTTP的生命周期通过Request来界定,也就是一个Request 一个Response,那么在HTTP1.0中,这次HTTP请求就结束了。
Websocket则不是
三,WebSocket具体过程是什么样的?
握手:
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
Origin: http://example.com
响应:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: chat
参考: WebSocket 是什么原理?为什么可以实现持久连接? - Ovear的回答 - 知乎 https://www.zhihu.com/question/20215561/answer/40316953
from fe-interview.
Related Issues (20)
- 【每日一题】- 2020-07-28 - Promise.all VS Promise. allSettled Promise.any VS Promise.race HOT 4
- 【每日一题】- 2020-08-03 - 多线程打印 HOT 5
- 【每日一题】- 2020-08-04 - 浏览器是如何解析 CSS rule 的? HOT 3
- 【每日一题】- 2020-08-05 - 运营商劫持 HOT 2
- 【每日一题】- 2020-08-06 - 讨厌的 Y HOT 3
- 【每日一题】- 2020-08-07 - 寻找祖先 HOT 5
- 【每日一题】- 2020-08-10 - JS 编程题 HOT 4
- 【节流防抖的概念弄混了】
- 【每日一题】- 2020-08-21 HOT 3
- 【每日一题】- 2020-08-25 - 编程范式 HOT 1
- 【每日一题】- 2020-09-02 - type A<T> = (x:T) => T; type B = <T>(x:T) => T; 的区别 HOT 3
- 【每日一题】- 2020-09-04 - 多个进程如何监听同一个端口 HOT 2
- 【每日一题】- 2020-09-15 - 响应头 content-type 的奇幻之旅 HOT 2
- 【每日一题】- 2020-10-09 - 以下 shell 的作用是什么? HOT 3
- 【每日一题】- 2020-10-16 - 分割数组 HOT 1
- 【每日一题】- 2020-10-21 - 字典分割 HOT 2
- 【每日一题】- 2020-04-19 - !!~A.indexOf(edge._label) 是什么意思? HOT 3
- 【每日一题】- 2021-07-12 数组的索引为什么从 0 开始?而不是从 1 开始? HOT 3
- 【开源自荐】推荐一个每日更新的前端面试题库
- 【开源自荐】SolidUI 一句话生成任何图形
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fe-interview.