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

wordpress没有function.php福州短视频seo公司

wordpress没有function.php,福州短视频seo公司,天长哪个广告公司做网站,能加速浏览器的加速器系列文章目录 一、SpringBoot连接MySQL数据库实例【tk.mybatis连接mysql数据库】 二、SpringBoot连接Redis与Redisson【代码】 三、SpringBoot整合WebSocket【代码】 四、SpringBoot整合ElasticEearch【代码示例】 文章目录 系列文章目录代码下载地址一、效果演示二、引入依赖…

系列文章目录

一、SpringBoot连接MySQL数据库实例【tk.mybatis连接mysql数据库】
二、SpringBoot连接Redis与Redisson【代码】
三、SpringBoot整合WebSocket【代码】
四、SpringBoot整合ElasticEearch【代码示例】


文章目录

  • 系列文章目录
  • 代码下载地址
  • 一、效果演示
  • 二、引入依赖
  • 三、WebSocketConfig
  • 四、SessionWrap
  • 五、WebSocketServer


代码下载地址

SpringBoot整合WebSocket【代码】


一、效果演示

测试链接
在这里插入图片描述

在这里插入图片描述

二、引入依赖

<!--    websocket    -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId><version>2.1.1.RELEASE</version>
</dependency>

三、WebSocketConfig

@Configuration
public class WebSocketConfig {@Beanpublic ServerEndpointExporter serverEndpointExporter() {return new ServerEndpointExporter();}
}

四、SessionWrap

SessionWrap 可根据具体需求自定义

@Data
public class SessionWrap {private String from;	// 连接Idprivate String type;	// 来凝结类型private Session session;private Date lastTime;
}

五、WebSocketServer

@Slf4j
@Component
@ServerEndpoint(value = "/api/websocket/{from}/{type}")
public class WebSocketServer {@Autowiredprivate MessageService messageService;public static WebSocketServer webSocketServer;// 所有的连接会话private static CopyOnWriteArraySet<SessionWrap> sessionList = new CopyOnWriteArraySet<>();private String from;private String type;@PostConstructpublic void init() {webSocketServer = this;webSocketServer.messageService = this.messageService;}/*** @author Lee* @date 2023/7/18 13:57* @description 创建连接*/@OnOpenpublic void onOpen(Session session, @PathParam(value = "from") String from, @PathParam(value = "type") String type) {this.from = from;this.type = type;try {// 遍历list,如果有会话,更新,如果没有,创建一个新的for (SessionWrap item : sessionList) {if (item.getFrom().equals(from) && item.getType().equals(type)) {item.setSession(session);item.setLastTime(new Date());log.info("【websocket消息】更新连接,总数为:" + sessionList.size());return;}}SessionWrap sessionWrap = new SessionWrap();sessionWrap.setFrom(from);sessionWrap.setType(type);sessionWrap.setSession(session);sessionWrap.setLastTime(new Date());sessionList.add(sessionWrap);log.info("【websocket消息】有新的连接,总数为:" + sessionList.size());} catch (Exception e) {log.info("【websocket消息】连接失败!错误信息:" + e.getMessage());}}/*** @author Lee* @date 2023/7/18 13:57* @description 关闭连接*/@OnClosepublic void onClose() {try {sessionList.removeIf(item -> item.getFrom().equals(from) && item.getType().equals(type));log.info("【websocket消息】连接断开,总数为:" + sessionList.size());} catch (Exception e) {log.info("【websocket消息】连接断开失败!错误信息:" + e.getMessage());}}/*** @author Lee* @date 2023/7/18 14:04* @description 发送消息*/@OnMessagepublic void onMessage(String message, Session session) {try {// 对消息进行处理JSONObject r = webSocketServer.messageService.insertMessage(message);String userId = r.getString("userId");for (SessionWrap item : sessionList) {// 发送消息的判断逻辑可根据需求修改if (item.getFrom().equals(userId) && item.getType().equals("test")) {item.getSession().getBasicRemote().sendText(r.toJSONString());log.info("【websocket消息】发送消息成功:" + r.toJSONString());}}} catch (Exception e) {log.info("【websocket消息】发送消息失败!错误信息:" + e.getMessage());}}@OnErrorpublic void onError(Session session, Throwable error) {log.error("用户错误,原因:"+error.getMessage());error.printStackTrace();}}
http://www.mmbaike.com/news/81390.html

相关文章:

  • 我的世界做图片的网站竞价推广账户托管费用
  • 汕头投资建设总公司网站seo搜索引擎优化案例
  • wordpress 淘宝windows10优化大师
  • 平台制作网站公司哪家好搜索引擎优化公司
  • 深圳龙华鸿宇大厦网站建设艾滋病多久可以查出来
  • 网站上的代码网页怎么做的抖音引流推广怎么做
  • wordpress仿站方法网络营销的模式有哪些?
  • 做b2b网站赚钱sem网络营销
  • 开发jsp网站汕头网站设计
  • 重庆 机械有限公司 江北网站建设百度快照
  • 大邑网站建设互联网宣传推广
  • 门户网站个人可以做淘宝seo 优化软件
  • 黑别人网站怎么做自己的网页
  • asp网站怎么仿站岳阳seo公司
  • 多个域名指向同一个网站软件编程培训学校排名
  • asp网站建设实验设计宁波seo整站优化软件
  • 域名如何指向网站爱站小工具
  • 有没有做美食的视频网站网站的seo是什么意思
  • 专门做美妆的网站网站内容优化关键词布局
  • 有哪个网站可以查别人做没做过牢吗网络营销推广实训报告
  • 试用网建设网站百度竞价开户费用
  • 网站反链如何做上海职业技能培训机构一览表
  • 泰州专业网站制作公司网红推广一般怎么收费
  • 大庆市建设局网站刘东网络营销的具体形式种类
  • 衡阳网站建设mdawl人民日报今日头条新闻
  • 济宁专业做优化的网站关键词是什么
  • 超变攻速传奇一秒20刀网站seo网络优化
  • 简单网站建设哪家便宜店铺推广软文案例
  • 长春住房和城乡建设部官方网站百度点击率排名有效果吗
  • 网站怎么做用什么软件网站外链是什么意思