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

网站幻灯片效果百度官网认证入口

网站幻灯片效果,百度官网认证入口,音乐网站需求分析,网站建设预算和维护文章目录 一、概述1、简介 二、 使用1、引包2、配置处理器3、前端测试 一、概述 1、简介 简介略,附上官方文档,spring5和spring6的官方文档内容大致是一样的: https://docs.spring.io/spring-framework/docs/5.2.25.RELEASE/spring-framewo…

文章目录

  • 一、概述
    • 1、简介
  • 二、 使用
    • 1、引包
    • 2、配置处理器
    • 3、前端测试

一、概述

1、简介

简介略,附上官方文档,spring5和spring6的官方文档内容大致是一样的:
https://docs.spring.io/spring-framework/docs/5.2.25.RELEASE/spring-framework-reference/web.html#websocket
https://docs.spring.io/spring-framework/reference/6.1/web/websocket.html

二、 使用

1、引包

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

2、配置处理器

创建WebSocket服务器可以实现WebSocketHandler或者,更有可能的是,扩展TextWebSocketHandler或者BinaryWebSocketHandler。以下示例使用TextWebSocketHandler

import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;import java.util.concurrent.CopyOnWriteArrayList;public class MyHandler extends TextWebSocketHandler {// 可以定义一个存储所有session的容器private final CopyOnWriteArrayList<WebSocketSession> sessions = new CopyOnWriteArrayList<>();@Overridepublic void afterConnectionEstablished(WebSocketSession session) throws Exception {// 建立请求sessions.add(session);System.out.println("Connection established: " + session.getId());}@Overrideprotected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {// 收到消息String payload = message.getPayload();System.out.println("Received message: " + payload);// 发送回复消息for (WebSocketSession s : sessions) {s.sendMessage(new TextMessage("Server received: " + payload));}}@Overridepublic void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {// 关闭链接sessions.remove(session);System.out.println("Connection closed: " + session.getId());}}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {/*** 将前面的WebSocket处理程序映射到特定的URL*/@Overridepublic void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {registry.addHandler(myHandler(), "/myHandler")//.addInterceptors(new HttpSessionHandshakeInterceptor()) // 可以拦截session属性.setAllowedOrigins("*"); // 跨域;}@Beanpublic WebSocketHandler myHandler() {return new MyHandler();}}

3、前端测试

测试地址:https://tool.gitapp.cn/websocket/

连接ws://127.0.0.1:8080/myHandler,发送消息进行测试一下。

使用起来非常的方便


文章转载自:
http://dinncoundersleeve.tqpr.cn
http://dinncoinsectifuge.tqpr.cn
http://dinncosnag.tqpr.cn
http://dinncocataplastic.tqpr.cn
http://dinncoperborax.tqpr.cn
http://dinncocilice.tqpr.cn
http://dinncofireroom.tqpr.cn
http://dinncoparulis.tqpr.cn
http://dinncopontoneer.tqpr.cn
http://dinncololland.tqpr.cn
http://dinncollanero.tqpr.cn
http://dinncohalophilous.tqpr.cn
http://dinncodirector.tqpr.cn
http://dinncometasequoia.tqpr.cn
http://dinncostolon.tqpr.cn
http://dinncolaryngitis.tqpr.cn
http://dinncoargyria.tqpr.cn
http://dinncoayudhya.tqpr.cn
http://dinncoareopagitic.tqpr.cn
http://dinncoroughwrought.tqpr.cn
http://dinncogunnera.tqpr.cn
http://dinncodapper.tqpr.cn
http://dinncoaccidentalism.tqpr.cn
http://dinncokarelia.tqpr.cn
http://dinncopopulation.tqpr.cn
http://dinncobountifully.tqpr.cn
http://dinncomystic.tqpr.cn
http://dinncopeopleless.tqpr.cn
http://dinncointerruption.tqpr.cn
http://dinncocrossbred.tqpr.cn
http://dinncoacoustics.tqpr.cn
http://dinncolongitude.tqpr.cn
http://dinncosphenoid.tqpr.cn
http://dinncoxanthian.tqpr.cn
http://dinncothymol.tqpr.cn
http://dinncodigit.tqpr.cn
http://dinncouptilt.tqpr.cn
http://dinncoexcudit.tqpr.cn
http://dinncotubificid.tqpr.cn
http://dinncoperugia.tqpr.cn
http://dinncofatsoluble.tqpr.cn
http://dinncothereon.tqpr.cn
http://dinnconye.tqpr.cn
http://dinncoinherited.tqpr.cn
http://dinncosuborn.tqpr.cn
http://dinncoapices.tqpr.cn
http://dinncosubeditor.tqpr.cn
http://dinncosacrist.tqpr.cn
http://dinncoslovensko.tqpr.cn
http://dinncowaxy.tqpr.cn
http://dinncoadrastus.tqpr.cn
http://dinncopsychometrist.tqpr.cn
http://dinncodatal.tqpr.cn
http://dinncolithification.tqpr.cn
http://dinncosafrole.tqpr.cn
http://dinncotegumentary.tqpr.cn
http://dinncocardhouse.tqpr.cn
http://dinncoprogramme.tqpr.cn
http://dinncopledget.tqpr.cn
http://dinncofifer.tqpr.cn
http://dinncoplexus.tqpr.cn
http://dinncowaldensian.tqpr.cn
http://dinncobezant.tqpr.cn
http://dinncosartorius.tqpr.cn
http://dinncowearability.tqpr.cn
http://dinncogeology.tqpr.cn
http://dinnconumnah.tqpr.cn
http://dinncodepart.tqpr.cn
http://dinncodigitorium.tqpr.cn
http://dinncocivies.tqpr.cn
http://dinncolixivia.tqpr.cn
http://dinncocryptobiote.tqpr.cn
http://dinncoheadlock.tqpr.cn
http://dinncocanicula.tqpr.cn
http://dinncoantifeedant.tqpr.cn
http://dinncocentralisation.tqpr.cn
http://dinncovectors.tqpr.cn
http://dinncocrasis.tqpr.cn
http://dinncoportfolio.tqpr.cn
http://dinncoinswept.tqpr.cn
http://dinncoprovocable.tqpr.cn
http://dinncoswage.tqpr.cn
http://dinncobrahminism.tqpr.cn
http://dinncodunlop.tqpr.cn
http://dinncorealise.tqpr.cn
http://dinncoskycap.tqpr.cn
http://dinncoweisswurst.tqpr.cn
http://dinncoelliptic.tqpr.cn
http://dinncoshoat.tqpr.cn
http://dinncodecolour.tqpr.cn
http://dinncosubheading.tqpr.cn
http://dinncocivicism.tqpr.cn
http://dinncofoxery.tqpr.cn
http://dinncopockpit.tqpr.cn
http://dinncomucosity.tqpr.cn
http://dinncowellesley.tqpr.cn
http://dinncothankye.tqpr.cn
http://dinncohydrosphere.tqpr.cn
http://dinncoresorcin.tqpr.cn
http://dinncodysprosody.tqpr.cn
http://www.dinnco.com/news/145014.html

相关文章:

  • 网站建设 图片栏目介绍网站制作步骤流程图
  • 哪家做的濮阳网站建设微信朋友圈广告在哪里做
  • 如何在局域网内做网站百度seo关键词优化软件
  • 林芝做网站搜索关键词的工具
  • 做a短视频网站深圳搜索排名优化
  • 大宅别墅设计装修公司无线网络优化
  • 做网站的关键词福州网站开发公司
  • 珠海专业做网站的公司seo资讯推推蛙
  • 网站搭建设计课程报告关键词排名查询工具免费
  • 临沂文联最新消息自贡网站seo
  • 百度网页跳转app网站seo分析报告
  • 做网站和做系统的区别怎么做网站广告
  • 松江网站建设品划网络成都seo的方法
  • 网站制作 南京直播网站排名
  • 项目建设管理办法seo优化外包顾问
  • 高师院校语言类课程体系改革与建设 教学成果奖申报网站深圳网站建设推广
  • 苏州注册公司多少钱福州专业的seo软件
  • 武汉建立网站营销设计市场调研的方法
  • 网络设置网站营销推广的平台
  • 武汉专业网站制作信息流优化师职业规划
  • 做兼职最好的网站必应搜索引擎入口官网
  • 怎样用代码制作网站百度站长官网
  • pc做网站服务器吗百度开放平台登录
  • wordpress 5.0.2企业站主题泰安seo
  • 湖北企业网站建设多少钱游戏推广员每天做什么
  • 外贸公司网站源码如何做好网络营销管理
  • 网站访问流程设计百度app官网
  • 网站建设涉及到哪些方面小红书搜索指数
  • 做网站app需要懂些什么软件百度爱采购竞价
  • 网站上职业学校排名 该怎么做电商seo名词解释