java webSocket服务端、客户端、心跳检测优雅解决
项目分为三个端,项目之间需要webSocket通信。
服务端
WebSocketConfig
package com.business.socket;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.socket.server.standard.ServerEndpointExporter;@Configurationpublic class WebSocketConfig { @Bean public ServerEndpointExporter serverEndpointExporter() { return new ServerEndpointExporter(); }}
WebSocketServer
package com.business.socket;import cn.hutool.core.collection.CollUtil;import cn.hutool.core.convert.Convert;import cn.hutool.core.exceptions.ValidateException;import cn.hutool.core.lang.Validator;import cn.hutool.core.util.StrUtil;import cn.hutool.json.JSONUtil;import cn.hutool.log.StaticLog;import com.user.vo.ws.SocMsgVo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.core.annotation.Order;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;import javax.websocket.*;import javax.websocket.server.PathParam;import javax.websocket.server.ServerEndpoint;import java.io.
来源地址:https://blog.csdn.net/javaXiaoAnRan/article/details/131762687