实现功能
- im系统
代码地址
- https://github.com/yutian1999/my-chat/tree/master
选用技术
- webSocket
为什么使用webSocket?
- webSocket协议支持服务端像客户端推送消息
http协议是一次请求一次响应,如果想要基于http协议实现只能客户端轮训,无论是性能还是实现上都远不及webSocket
依赖技术
- Spring-boot webSocket
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
目录结构

设计实现

核心代码
public class SocketSession implements Serializable {
private static final Map<String,Session> sessions = new HashMap<>();
/**
* 获取session
* @param userId 用户id
* @return session
*/
public static Session getS



被折叠的 条评论
为什么被折叠?



