分类
http
https
- 加密的https , 用了非对称加密来传送密钥, 然后再用对称加密
websocket
- 持久连接
- 客户端和服务端通信
webRTC
- 点对点连接, 不需要服务器
分类2
短连接
- 每次都要3次握手, 建立tcp连接
长连接
- 比如有一个耗时很长的任务, 客户端想知道完成了没有, 有两种办法
- 轮询:每隔几秒钟发个http请求问一下服务器
- 长连接: 发一个http请求, 服务器收到, 一直不响应, 直到任务结束后响应, 这样时间很长, 但连接一直不断
持久链接
websocket
- 第一次用http建立链接, 后面的都是tcp通信
- 后面每次发送消息, 都不需要握手
- 双向通信
EventSoure
- 服务端 -> 客户端 单向通信
- 参考文章: blog.tericcabrel.com/implement-s…
webRTC vs webSocket
They’re quite different in the way they work but basically:
- WebSockets were built for sending data in real time between the client and server. Websockets can easily accommodate media.
- WebRTC was built for sending media peer 2 peer between 2 clients. It can accommodate data.