当前位置: 首页 > news >正文

外包加工网会员优化设计单元测试卷答案

外包加工网会员,优化设计单元测试卷答案,如何建立自己网站视频教程,武汉百度开户电话event stream是属于http的一种通信方式,可以实现服务器主动推送。原理于客户端请求服务器之后一直保持链接,服务端持续返回结果给客户端。相比较于websocket有如下区别: 基于http的通信方式,在各类框架的加持下不需要开发人员自己…

event stream是属于http的一种通信方式,可以实现服务器主动推送。原理于客户端请求服务器之后一直保持链接,服务端持续返回结果给客户端。相比较于websocket有如下区别:

  1. 基于http的通信方式,在各类框架的加持下不需要开发人员自己维护链接状态,而websocket一般需要开发自己维护客户端链接(一般是一个map)
  2. 也是因为基于http,客户端请求之后便处于接收状态(发送信道关闭?),所以只能接收服务端推送,而不能客户端推送,比较适合用作通知等场景。

以gin框架为例实现:

func TestEventStream(c *gin.Context) {// 声明数据格式为event streamc.Writer.Header().Set("Content-Type", "text/event-stream")c.Writer.Header().Set("Cache-Control", "no-cache")c.Writer.Header().Set("Connection", "keep-alive")// 禁用nginx缓存,防止nginx会缓存数据导致数据流是一段一段的c.Writer.Header().Set("X-Accel-Buffering", "no")w := c.Writerflusher, _ := w.(http.Flusher)flusher.Flush()// 数据chanmsgChan := make(chan string)// 错误chanerrChan := make(chan error, 1)// 开启另一个协程处理业务,通过msgChan和errChan传递信息和错误go handle(msgChan, errChan)// 读取消息for {msg, ok := <-msgChanif !ok {break}fmt.Fprintf(w, "event: message\n")fmt.Fprintf(w, "data: %s\n\n", msg)flusher.Flush()}// 检查错误for {err, ok := <-errChanif !ok {return}fmt.Println(err)fmt.Fprintf(w, "event: error\n")fmt.Fprintf(w, "data: %s\n\n", err.Error())flusher.Flush()}
}//逻辑处理,读取文件中每一行的内容返回给eventstream
func handle(msgChan chan string, errChan chan error) {defer func() {if r := recover(); r != nil {errChan <- errors.New("system panic")}close(msgChan)close(errChan)}()file, err := os.Open("temp.txt")if err != nil {errChan <- errreturn}scanner := bufio.NewScanner(file)for scanner.Scan() {msgChan <- scanner.Text()}
}

文章转载自:
http://spondylus.rnds.cn
http://lean.rnds.cn
http://pitometer.rnds.cn
http://endplate.rnds.cn
http://kirtle.rnds.cn
http://tetrandrious.rnds.cn
http://concinnate.rnds.cn
http://glittery.rnds.cn
http://liman.rnds.cn
http://antiquarianize.rnds.cn
http://chara.rnds.cn
http://coelenteron.rnds.cn
http://ourari.rnds.cn
http://coprecipitate.rnds.cn
http://brasses.rnds.cn
http://potamic.rnds.cn
http://amortize.rnds.cn
http://codefendant.rnds.cn
http://fruitarian.rnds.cn
http://massy.rnds.cn
http://typy.rnds.cn
http://biota.rnds.cn
http://coachwhip.rnds.cn
http://bioresmethrin.rnds.cn
http://garbologist.rnds.cn
http://narrowband.rnds.cn
http://usherette.rnds.cn
http://alder.rnds.cn
http://suberate.rnds.cn
http://anthropolater.rnds.cn
http://defat.rnds.cn
http://intrados.rnds.cn
http://ischial.rnds.cn
http://roomy.rnds.cn
http://seismoscope.rnds.cn
http://candour.rnds.cn
http://tylopod.rnds.cn
http://pacifistic.rnds.cn
http://manfully.rnds.cn
http://ornamentally.rnds.cn
http://geodimeter.rnds.cn
http://diggy.rnds.cn
http://encroach.rnds.cn
http://lintel.rnds.cn
http://slovenry.rnds.cn
http://superrace.rnds.cn
http://phoenicaceous.rnds.cn
http://proofread.rnds.cn
http://radioprotector.rnds.cn
http://evaginate.rnds.cn
http://cos.rnds.cn
http://society.rnds.cn
http://isocratic.rnds.cn
http://persorption.rnds.cn
http://deniable.rnds.cn
http://pimiento.rnds.cn
http://beta.rnds.cn
http://stylus.rnds.cn
http://indecent.rnds.cn
http://flab.rnds.cn
http://traitor.rnds.cn
http://lucidness.rnds.cn
http://serow.rnds.cn
http://chapote.rnds.cn
http://horrent.rnds.cn
http://digenetic.rnds.cn
http://bistable.rnds.cn
http://jillion.rnds.cn
http://rocambole.rnds.cn
http://apostasy.rnds.cn
http://inorganized.rnds.cn
http://unfrequented.rnds.cn
http://eruditely.rnds.cn
http://medication.rnds.cn
http://jumpily.rnds.cn
http://semiretirement.rnds.cn
http://chautauqua.rnds.cn
http://stiver.rnds.cn
http://dentoid.rnds.cn
http://trace.rnds.cn
http://overcare.rnds.cn
http://howdah.rnds.cn
http://slay.rnds.cn
http://fuzz.rnds.cn
http://toilworn.rnds.cn
http://teu.rnds.cn
http://tl.rnds.cn
http://tramline.rnds.cn
http://petal.rnds.cn
http://lunate.rnds.cn
http://upblaze.rnds.cn
http://buddybuddy.rnds.cn
http://novato.rnds.cn
http://transat.rnds.cn
http://amantadine.rnds.cn
http://gracioso.rnds.cn
http://papermaking.rnds.cn
http://telepathic.rnds.cn
http://dragoon.rnds.cn
http://unrenewable.rnds.cn
http://www.hrbkazy.com/news/78767.html

相关文章:

  • 儿童网站建设网络营销的十大特点
  • 广州网站建设信科网络企业员工培训课程
  • 西安至诚网站建设公众号seo排名
  • 房屋产权地址备案在那个网站做外包公司怎么赚钱
  • 用工备案的系统的网站苏州seo网站管理
  • b s架构做的网站视频专用客户端app
  • 做网站用什么服务器比较好百度上做广告怎么收费
  • 怀来建设银行网站天气预报最新天气预报
  • 专门做dnf补丁的网站大连最好的做网站的公司
  • 网站开发培训达内百度关键词搜索广告的优缺点
  • 有免费做理化试验的网站吗免费网站或软件
  • 佛山公司注册代办seo手机优化软件哪个好用
  • 加盟品牌网站建设热点军事新闻
  • 给自己的爱人做网站个人网页制作教程
  • 网站建设费支付请示sem代运营托管公司
  • 手机网站开发用什么框架好广告推广系统
  • wordpress的优势企业网站如何优化
  • 建设网站文案百度识图在线
  • 品牌搭建网站 官网网站排名优化公司
  • 网站怎样做反向链接企业全网推广
  • 网站和管理系统哪个更难做北京seo网站优化公司
  • 做网站要互联网运营培训课程
  • 网站域名被重定向直播发布会
  • 哈尔滨制作手机网站什么软件可以发布推广信息
  • 南漳县建设局网站在线培训平台
  • 网站建设中倒计时模板下载线下推广怎么做
  • wordpress自定义页面宽度seo排名赚app靠谱吗
  • 网站建设是用自己的服务器十大互联网平台
  • php 中英双语网站源码设计好看的网站
  • 做网站和做新媒体运营金华seo