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

一个网站怎么做流量统计贵州seo推广

一个网站怎么做流量统计,贵州seo推广,开个网站建设公司多少钱,投资公司名称概述 基于spingboot的websocket多人聊天系统。包括订阅,广播、点对点单人聊天,多人聊天室功能。 详细 一、运行效果 简单示例 广播 单人聊天 多人聊天室 二、相关代码 websocket配置 package com.iamgpj.demowebsocket.config;import com.iamgpj.d…

概述

基于spingboot的websocket多人聊天系统。包括订阅,广播、点对点单人聊天,多人聊天室功能。

详细

一、运行效果

简单示例

image.png

广播

image.png

单人聊天

image.png

多人聊天室

image.png

二、相关代码

websocket配置

package com.iamgpj.demowebsocket.config;import com.iamgpj.demowebsocket.v4.SocketChannelInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;import javax.websocket.server.ServerEndpointConfig;/*** @author Ives* @date 2020/4/20 13:51*/
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends ServerEndpointConfig.Configurator implements WebSocketMessageBrokerConfigurer {/*** 注册端点,发布或者订阅消息的时候需要连接此端点* addEndpoint websocket的端点,客户端需要注册这个端点进行链接* setAllowedOrigins 非必须,*表示允许其他域进行连接,跨域* withSockJS 允许客户端利用sockjs进行浏览器兼容性处理* @param registry*/@Overridepublic void registerStompEndpoints(StompEndpointRegistry registry) {registry.addEndpoint("/ws/endpoints-websocket")//.setAllowedOrigins("*").withSockJS();}/*** 配置消息代理* @param registry*/@Overridepublic void configureMessageBroker(MessageBrokerRegistry registry) {// 设置服务器广播消息的基础路径registry.enableSimpleBroker("/topic", "/user");// 设置客户端订阅消息的基础路径registry.setApplicationDestinationPrefixes("/app");}/** 配置频道拦截器,用于聊天室 */@Overridepublic void configureClientInboundChannel(ChannelRegistration registration) {registration.interceptors(new SocketChannelInterceptor());}
}

聊天室程序

package com.iamgpj.demowebsocket.v4;import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;import java.time.LocalDateTime;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;/*** @author Ives* @date 2020/4/21 11:13*/
@Service
@Slf4j
public class ChatRoomService {@Autowiredprivate SimpMessagingTemplate template;/*** 模拟数据库中存储的用户*/public static Map<String, String> userMap = new HashMap<>();/*** 保存当前在线用户* 实际应该存储于redis等可持久化缓存服务器中,做到数据共享*/public static Map<String, String> onlineUserMap = new HashMap<>();/** 初始化数据 */static {userMap.put("张三", "111111");userMap.put("李四", "111111");userMap.put("王五", "111111");userMap.put("赵六", "111111");userMap.put("陈七", "111111");}/*** 每两秒给客户端推送当前在线用户*/@Scheduled(fixedRate = 2000)public void pushOnlineUser() {Collection<String> users = onlineUserMap.values();log.info("【聊天室在线用户】={}", users);template.convertAndSend("/topic/onlineUser", users);}/*** 推送聊天消息* @param inMessage 内容*/public void pushChatRoom(InMessage inMessage) {OutMessage outMessage = new OutMessage();BeanUtils.copyProperties(inMessage, outMessage);outMessage.setPushTime(LocalDateTime.now());template.convertAndSend("/topic/chatRoom", outMessage);}
}

三、代码结构

image.png

四、相关说明

1、项目前段使用bootstrap框架,使用maven引入webjars作为样式文件。

2、访问路径分别为

    http://localhost:8080/v1/index.html

    http://localhost:8080/v2/index.html

    http://localhost:8080/v3/tom.html

    http://localhost:8080/v3/jerry.html

    http://localhost:8080/v4/index.html

3、聊天室请分别使用不同浏览器登录测试。登录名可以为,张三、李四、王五、赵六....

http://www.hkea.cn/news/696394/

相关文章:

  • 怎样找到正规代加工网站百度地图3d实景地图
  • 潍坊网站建设公司网站搭建免费
  • 惠州做网站好的公司下载百度语音导航地图安装
  • 春节网站怎么做小说排行榜百度搜索风云榜
  • 商城服务是什么软件seo是指什么岗位
  • 无锡网站建设有限公司网站快速收录的方法
  • 网站建设通报推广网站多少钱
  • 网络推广公司成都seo排名优化教程
  • 一台手机登录微信网页版西安优化外
  • 如何做旅游攻略网站长沙seo优化推荐
  • 长春火车站电话咨询电话快排seo
  • 龙城建设网站公司网站内容优化方法
  • 南通网站建设搭建网站卖链接
  • 驻马店市做网站seo臻系统
  • 找公司做网站怎么图片都要自己找百度推广官网电话
  • 网站小样用什么做seo外链平台热狗
  • 建站点的步骤sem是什么
  • 深圳专业做网站的衡水网站优化推广
  • 徐汇科技网站建设2345中国最好的网址站
  • 邢台论坛吧百度seo收录软件
  • 做国外服务器网站吗怎么让百度搜索靠前
  • 做动态图网站有哪些自建站怎么推广
  • web网站开发课程设计报告seo技术培训沈阳
  • 会宁网站建设公司网站优化助手
  • 网站设计制作体会2023年5月最新疫情
  • 月亮湾设计有限公司网站南宁seo产品优化服务
  • 福田欧曼服务站电话上海高端seo公司
  • 高端网站建设哪家好谷歌seo和百度seo
  • 前端写一个页面多少钱海口网站关键词优化
  • 浦东新区建设局官方网站东莞seo关键词