检测模块调整
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.njcn.gather.detection.util.socket;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @Description: webSocket存储的通道
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/11 13:04
|
||||
*/
|
||||
public class WebServiceManager {
|
||||
private static final Map<String, Channel> userSessions = new ConcurrentHashMap<>();
|
||||
|
||||
public static void addUser(String userId, Channel channel) {
|
||||
userSessions.put(userId, channel);
|
||||
}
|
||||
|
||||
public static void removeUser(String userId) {
|
||||
userSessions.remove(userId);
|
||||
}
|
||||
|
||||
public static Channel getChannelByUserId(String userId) {
|
||||
return userSessions.get(userId);
|
||||
}
|
||||
|
||||
public static void sendMsg(String msg) {
|
||||
Channel userId = userSessions.get("userId");
|
||||
TextWebSocketFrame wd1 = new TextWebSocketFrame(msg);
|
||||
userId.writeAndFlush(wd1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user