Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

服务端推送的几种方式 #35

Open
xingbofeng opened this issue Jul 27, 2018 · 0 comments
Open

服务端推送的几种方式 #35

xingbofeng opened this issue Jul 27, 2018 · 0 comments

Comments

@xingbofeng
Copy link
Owner

xingbofeng commented Jul 27, 2018

服务端推送是现今Web开发过程中最常见的需求。例如:

  • 即时聊天工具
  • H5网络游戏
  • 消息通知

一般的服务器推送包括:

  • 最简单的是客户端轮询的方式,在客户端创建一个定时器,每隔一定的时间去请求服务端,每次请求检查状态变化以判断服务端是否有新数据更新。
  • 基于 AJAX 的长轮询(long-polling)方式,服务器在一段时间后再返回信息;
  • HTTP Streaming,通过iframe<script>标签完成数据的传输;
  • TCP长连接/WebSocket,可以实现服务器主动发送数据至网页端,它和HTTP一样,是一个基于HTTP的应用层协议,跑的是TCP,所以本质上还是个长连接,双向通信,意味着服务器端和客户端可以同时发送并响应请求,而不再像HTTP的请求和响应
  • SSE: Server-Sent Events,这是通过http协议变通实现的,通过服务端向客户端声明,接下来是要发送的是流信息,本质上就是完成一次耗时长的下载。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant