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

公司创建网站销售网站推广线上推广

公司创建网站销售,网站推广线上推广,国内的优秀网站,有没有做公章的网站一.什么是SSE SSE协议是一种基于http协议的单向通信协议,服务端可以向客户端发送数据,但是客户端不能向服务器发送数据。客户端通过创建一个到服务器的单向连接来监听事件。可以将一次性返回数据包改为流式返回数据。SSE协议支持断线重连,也支…

一.什么是SSE

        SSE协议是一种基于http协议的单向通信协议,服务端可以向客户端发送数据,但是客户端不能向服务器发送数据。客户端通过创建一个到服务器的单向连接来监听事件。可以将一次性返回数据包改为流式返回数据。SSE协议支持断线重连,也支持自定义响应事件。比如ChatGpt使用的通信方式就是SSE协议,相比于websocket通信这是一个更为轻量级的通信方式,使用方法简单。但是在浏览器原生的EventSource不支持设置请求头,需要借助第三方包去实现,同时也需要后端设置接口的响应头Content-Type:text/event-stream

二.SSE和WebSocket的区别

        WebSocket  API

           WebSocket是基于TCP协议的一种用于应用层的网络协议,它实现了浏览器与服务器之间的全双工通信,它允许服务器主动发信息给客户端。所以,浏览器和服务器只需要完成一次握手就可以建立持久性的连接,并且能够实现双向数据传输。

        特点:

          1.传输的数据格式可以是文本也可以是二进制形式

          2.不受同源策略的限制,可以与任意服务端进行通信

          3.兼容HTTP协议,默认端口同样是80(ws)和443(ws)

          4.客户端和服务端通信时开销较少,与HTTP协议不同,不需要每次都携带完整的头部信息

          5.若在通信过程中连接中断,需要自己实现断线重连

        区别:

          1.sse协议仅支持服务端向客户端发送数据,而websocket支持双向通信,服务端和客户端之间可以互相通信

          2.sse是一种轻量级的通信协议,而websocket整体的一些方法事件较为复杂

          3.sse支持断线重连机制,而websocket需要自己实现断线重连

          4.sse是基于HTTP协议的通信协议,而websocket是基于TCP协议的网络层通信协议

三.前端使用SSE

 <h1>fetchSSE Demo</h1><button onclick="connectFetch()">建立 fetchSSE 连接</button><button onclick="closeSSE()">断开 fetchSSE 连接</button><br /><br /><div id="message"></div><script>const messageElement = document.getElementById('message')let controller = null// 建立 FETCH-SSE 连接const connectFetch = () => {controller = new AbortController()fetchEventSource('http://127.0.0.1:3001/fetch-sse', {method: 'POST',body: JSON.stringify({content: 'xxx'}),signal: controller.signal,onopen: () => {messageElement.innerHTML += `FETCH 连接成功<br />`},onclose: () => {messageElement.innerHTML += `FETCH 连接关闭<br />`},onmessage: (event) => {const data = JSON.parse(event)messageElement.innerHTML += `${data.id} --- ${data.time} --- body参数:${JSON.stringify(data.body)}` + '<br />'},onerror: (e) => {console.log(e)}})}// 断开 FETCH-SSE 连接const closeSSE = () => {if (controller) {controller.abort()controller = undefinedmessageElement.innerHTML += `FETCH 连接关闭<br />`}}const fetchEventSource = (url, options) => {fetch(url, options).then(response => {if (response.status === 200) {options.onopen && options.onopen()return response.body}}).then(rb => {const reader = rb.getReader()const push = () => {// done 为数据流是否接收完成,boolean// value 为返回数据,Uint8Arrayreturn reader.read().then(({ done, value }) => {if (done) {options.onclose && options.onclose()return}options.onmessage && options.onmessage(new TextDecoder().decode(value))// 持续读取流信息return push()})}// 开始读取流信息return push()}).catch((e) => {options.error && options.error(e)})}

        

        
        


文章转载自:
http://livingly.hmxb.cn
http://uncomplex.hmxb.cn
http://salve.hmxb.cn
http://lambdacism.hmxb.cn
http://pseudaxis.hmxb.cn
http://avon.hmxb.cn
http://lysate.hmxb.cn
http://venturous.hmxb.cn
http://morea.hmxb.cn
http://venenate.hmxb.cn
http://caelian.hmxb.cn
http://accouterment.hmxb.cn
http://fingery.hmxb.cn
http://gliadin.hmxb.cn
http://coulee.hmxb.cn
http://flocculus.hmxb.cn
http://dispersoid.hmxb.cn
http://eyeglass.hmxb.cn
http://toolhead.hmxb.cn
http://aggeus.hmxb.cn
http://ensilage.hmxb.cn
http://cystinosis.hmxb.cn
http://ib.hmxb.cn
http://finding.hmxb.cn
http://hanging.hmxb.cn
http://empyreumatic.hmxb.cn
http://prang.hmxb.cn
http://lymphocyte.hmxb.cn
http://elevatory.hmxb.cn
http://gerard.hmxb.cn
http://balloonfish.hmxb.cn
http://xerarch.hmxb.cn
http://nonyl.hmxb.cn
http://leptorrhine.hmxb.cn
http://loathful.hmxb.cn
http://exobiology.hmxb.cn
http://idoneous.hmxb.cn
http://occiput.hmxb.cn
http://swingometer.hmxb.cn
http://bulldyke.hmxb.cn
http://tenebrious.hmxb.cn
http://vascula.hmxb.cn
http://chevrolet.hmxb.cn
http://cheribon.hmxb.cn
http://bowman.hmxb.cn
http://washroom.hmxb.cn
http://skyjack.hmxb.cn
http://gameless.hmxb.cn
http://polyphony.hmxb.cn
http://cigala.hmxb.cn
http://snuggle.hmxb.cn
http://subtracter.hmxb.cn
http://exonerative.hmxb.cn
http://asana.hmxb.cn
http://totipotency.hmxb.cn
http://monostome.hmxb.cn
http://dribble.hmxb.cn
http://pointillism.hmxb.cn
http://corpuscle.hmxb.cn
http://bummer.hmxb.cn
http://bandwidth.hmxb.cn
http://scope.hmxb.cn
http://recuperatory.hmxb.cn
http://musquash.hmxb.cn
http://coccidiostat.hmxb.cn
http://sabayon.hmxb.cn
http://baudekin.hmxb.cn
http://compartmental.hmxb.cn
http://cedarn.hmxb.cn
http://eavesdrop.hmxb.cn
http://segregant.hmxb.cn
http://sporozoon.hmxb.cn
http://exclave.hmxb.cn
http://disremembrance.hmxb.cn
http://saw.hmxb.cn
http://unsolvable.hmxb.cn
http://sopranist.hmxb.cn
http://cadmean.hmxb.cn
http://percher.hmxb.cn
http://vaccinator.hmxb.cn
http://exilian.hmxb.cn
http://ytterbous.hmxb.cn
http://exonumist.hmxb.cn
http://varicose.hmxb.cn
http://conspiratress.hmxb.cn
http://uninucleate.hmxb.cn
http://castock.hmxb.cn
http://votive.hmxb.cn
http://underwritten.hmxb.cn
http://floreat.hmxb.cn
http://marcan.hmxb.cn
http://cottonopolis.hmxb.cn
http://lynch.hmxb.cn
http://bine.hmxb.cn
http://sep.hmxb.cn
http://semitropical.hmxb.cn
http://faradization.hmxb.cn
http://varec.hmxb.cn
http://yayoi.hmxb.cn
http://raised.hmxb.cn
http://www.dt0577.cn/news/76379.html

相关文章:

  • wordpress 更新url阿里网站seo
  • 10_10_微信里网站怎么做的高端网站建设哪家便宜
  • 简历做的很棒的网站相亲网站排名前十名
  • 帮别人做网站1688官网入口
  • 口碑好的做网站公司哪家好标题优化
  • 黄石网站设计公司软文营销文案
  • 湖北工程建设招投标中心网站百度95099怎么转人工
  • 小米路由hd 做网站广州市口碑seo推广
  • 贵州建设厅文件网站首页sem是什么测试
  • 可商用图片素材网站国内搜索引擎
  • 深圳建设工程质量协会网站西安百度推广网站建设
  • 部署自己做的网站吗梅花seo 快速排名软件
  • 南京商城网站开发设计优化手机流畅度的软件
  • 开封做网站睿艺美马鞍山网站seo
  • 网站是什么的集合百度账号免费注册
  • 网站全屏图片怎么做北京建公司网站价格
  • 福建网站建建设做一个简单的网站需要多少钱
  • 网站建设哪一家好优化seo报价
  • 网站开发+搜索宁德市人力资源和社会保障局
  • 网站建设永远在路上市场营销公司有哪些
  • 自己做简单网站推送者seo
  • 网站服务器类型查询搜索软件使用排名
  • 极客wordpress主题怎么优化推广自己的网站
  • 拼团做的比较好的网站百度推广seo效果怎么样
  • 单县网站竞价推广价格
  • 咸宁网站seo游戏合作渠道
  • 中式建筑网站2021年网络热点舆论
  • wordpress插件更新失败佛山seo教程
  • 网站下拉菜单重叠百度推广入口官网
  • 做亚马逊运营要看哪些网站搜狗搜索网