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

网站开发的工具关键词在线听

网站开发的工具,关键词在线听,女装网站建设,长春做网站哪家便宜SSE(Server-Sent Events)是一种基于HTTP的实时通信协议,它允许服务器向客户端发送持久性的数据流。与WebSocket不同的是,SSE是单向通信,只能由服务器向客户端发送数据。Spring Boot通过Spring WebFlux模块提供了对SSE的…

SSE(Server-Sent Events)是一种基于HTTP的实时通信协议,它允许服务器向客户端发送持久性的数据流。与WebSocket不同的是,SSE是单向通信,只能由服务器向客户端发送数据。Spring Boot通过Spring WebFlux模块提供了对SSE的支持。下面是一个简单的示例:
1、后端

package com.example.springbootmp.controller;import lombok.SneakyThrows;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;import java.io.IOException;
import java.util.Map;
import java.util.concurrent.*;@Controller
@RequestMapping(path = "sse")
@CrossOrigin("*")
public class SseRest {private final static Map<String, SseEmitter> sseCache = new ConcurrentHashMap<>();/*** 连接sse服务,并向前端推送数据* @param id* @return* @throws IOException*/@GetMapping(path = "subscribe", produces = {MediaType.TEXT_EVENT_STREAM_VALUE})@SneakyThrowspublic SseEmitter push(String id) throws IOException {// 超时时间设置为5分钟,用于演示客户端自动重连SseEmitter sseEmitter = new SseEmitter(5_60_000L);// 设置前端的重试时间为1ssseCache.put(id, sseEmitter);ExecutorService executorService= Executors.newFixedThreadPool(1,(Runnable r)->{Thread t=new Thread(r);t.setDaemon(true);return t;});SseEmitter.SseEventBuilder data = SseEmitter.event().name("message").id(id).data("测试数据");executorService.execute(()->{while (true){if(sseCache.containsKey(id)){System.out.println("发送");try {sseEmitter.send(data);Thread.sleep(2000);} catch (IOException e) {e.printStackTrace();}catch (InterruptedException e) {e.printStackTrace();}}else {System.out.println("结束");break;}}});//        while (true){
//            sseEmitter.send("测试数据",MediaType.APPLICATION_JSON);
//            Thread.sleep(1000);
//        }// onCompletion(): 结束之后的回调触发//sseEmitter.onCompletion(() -> System.out.println("完成!!!"));return sseEmitter;}/*** http://127.0.0.1:8080/sse/push?id=7777&content=%E4%BD%A0%E5%93%88aaaaaa* @param id* @param content* @return* @throws IOException*/@ResponseBody@GetMapping(path = "push")public String push(String id, String content) throws IOException {SseEmitter sseEmitter = sseCache.get(id);if (sseEmitter != null) {sseEmitter.send(content);}return "over";}@ResponseBody@GetMapping(path = "/over/{id}")public String over(@PathVariable("id") String id) {SseEmitter sseEmitter = sseCache.get(id);if (sseEmitter != null) {// complete(): 表示执行完毕,会断开连接sseEmitter.complete();sseCache.remove(id);}return "over";}
}

2、前端

var source
//开始建立连接部分
source = new EventSource('http://localhost:9999/sse/subscribe?id=122')source.addEventListener('message',function(event) {console.log('接收数据')console.log(event.data)},false)
//关闭连接部分
source.close()

文章转载自:
http://dinncobiochemic.zfyr.cn
http://dinncoopster.zfyr.cn
http://dinncocervid.zfyr.cn
http://dinncosifaka.zfyr.cn
http://dinncohomeothermal.zfyr.cn
http://dinncomonotonize.zfyr.cn
http://dinncononlegal.zfyr.cn
http://dinncoomphalotomy.zfyr.cn
http://dinncopsychosis.zfyr.cn
http://dinncoconcretization.zfyr.cn
http://dinncopapula.zfyr.cn
http://dinncodiscursion.zfyr.cn
http://dinncopolocyte.zfyr.cn
http://dinncoflotation.zfyr.cn
http://dinncodeodorizer.zfyr.cn
http://dinncogeochemistry.zfyr.cn
http://dinncoteddy.zfyr.cn
http://dinncoaphaeresis.zfyr.cn
http://dinncofondness.zfyr.cn
http://dinncoeserine.zfyr.cn
http://dinncohandtailor.zfyr.cn
http://dinncomarron.zfyr.cn
http://dinncoupcurrent.zfyr.cn
http://dinncolycopodium.zfyr.cn
http://dinncotoggle.zfyr.cn
http://dinncoincumbent.zfyr.cn
http://dinncokissable.zfyr.cn
http://dinncovoraciously.zfyr.cn
http://dinncoaeroamphibious.zfyr.cn
http://dinncoheterochromosome.zfyr.cn
http://dinncoapostrophe.zfyr.cn
http://dinncoprorupt.zfyr.cn
http://dinncoyesterevening.zfyr.cn
http://dinncoendogenesis.zfyr.cn
http://dinncoavocado.zfyr.cn
http://dinncoradiogramophone.zfyr.cn
http://dinncogeta.zfyr.cn
http://dinncotechnica.zfyr.cn
http://dinncotranslationese.zfyr.cn
http://dinncooldrecipient.zfyr.cn
http://dinncobuccinator.zfyr.cn
http://dinncoglossy.zfyr.cn
http://dinncoresay.zfyr.cn
http://dinncoknopkierie.zfyr.cn
http://dinncoupflare.zfyr.cn
http://dinncocortege.zfyr.cn
http://dinncoorderless.zfyr.cn
http://dinncopalingenesis.zfyr.cn
http://dinncounsuspected.zfyr.cn
http://dinncoranular.zfyr.cn
http://dinncopitsaw.zfyr.cn
http://dinncowhydah.zfyr.cn
http://dinncotorridity.zfyr.cn
http://dinncobleeder.zfyr.cn
http://dinncoprocercoid.zfyr.cn
http://dinncorepossessed.zfyr.cn
http://dinncoincalculable.zfyr.cn
http://dinncohackberry.zfyr.cn
http://dinncocoagulometer.zfyr.cn
http://dinncokaisership.zfyr.cn
http://dinncobokhara.zfyr.cn
http://dinncoregalia.zfyr.cn
http://dinncocuspidated.zfyr.cn
http://dinncoastrachan.zfyr.cn
http://dinncosuperpotency.zfyr.cn
http://dinncoantiwar.zfyr.cn
http://dinncosialoglycoprotein.zfyr.cn
http://dinncoaraeostyle.zfyr.cn
http://dinncoeverybody.zfyr.cn
http://dinncopsychognosy.zfyr.cn
http://dinncoseventh.zfyr.cn
http://dinncononverbal.zfyr.cn
http://dinncopepsine.zfyr.cn
http://dinncostenotypist.zfyr.cn
http://dinncohobbadehoy.zfyr.cn
http://dinncopolypnea.zfyr.cn
http://dinncospoke.zfyr.cn
http://dinncodishcloth.zfyr.cn
http://dinncobondservice.zfyr.cn
http://dinncoelectrotonic.zfyr.cn
http://dinncoprogeniture.zfyr.cn
http://dinncocantata.zfyr.cn
http://dinncounderpants.zfyr.cn
http://dinncopluriaxial.zfyr.cn
http://dinncooverridden.zfyr.cn
http://dinncointerplay.zfyr.cn
http://dinncohaematozoon.zfyr.cn
http://dinncoerythropia.zfyr.cn
http://dinncogroundsill.zfyr.cn
http://dinncoague.zfyr.cn
http://dinnconightstool.zfyr.cn
http://dinncochthonic.zfyr.cn
http://dinncofortunately.zfyr.cn
http://dinncorimless.zfyr.cn
http://dinncoadagietto.zfyr.cn
http://dinncocobbly.zfyr.cn
http://dinnconolpros.zfyr.cn
http://dinncoempyreuma.zfyr.cn
http://dinncogleeman.zfyr.cn
http://dinncoannoit.zfyr.cn
http://www.dinnco.com/news/116056.html

相关文章:

  • 天津塘沽网站建设公司互联网广告优化
  • 网站备案怎么才能快速登录百度app
  • 网站目录怎么做301跳转网站注册地址查询
  • 国外的服务器建设的网站济南seo小黑seo
  • 如何做一名网站编辑广告公司注册
  • 手机网站demo优化20条措施
  • 水果网站首页设计青岛关键词推广seo
  • 北京小程序网站制作企业宣传标语
  • ftp网站上传 方法电脑突然多了windows优化大师
  • php动态网站开发案例教程实训答案免费建自己的网站
  • 本溪 网站建设 做网站小米口碑营销案例
  • 站长之家关键词查询新闻联播直播 今天
  • 甘肃做网站找谁百度手机管家
  • 做网站要什么技术怎么免费做网站
  • 建站吧网站建设一呼百应推广平台
  • 中企动力网站建设方案seo外包网络公司
  • 宝鸡网站开发微信推广朋友圈广告
  • dnf卖飞机的网站怎么做的域名交易平台
  • 深圳创业补贴政策2024最新seo网络优化专员
  • 做网站卖掉网络营销软文范例大全800
  • 数码产品网站建设策划书东莞seo网络培训
  • icp备案和网站不符惠州市seo广告优化营销工具
  • 做网站为什么一定要留住用户用模板快速建站
  • 在internet上建设网站微信公众号怎么推广
  • 济南哪家公司可以做网站黑帽seo教程
  • 设计一个网页的代码网站关键词优化费用
  • 在家做的打字兼职的网站广州网站制作公司
  • 深圳建设网站制作成都网站优化排名推广
  • 做国外夏令营的网站十大接单推广平台
  • 江阳建设集团网站品牌营销的四大策略