private static CopyOnWriteArraySet webSockets = new CopyOnWriteArraySet<>();
private static Map<Long, Session> sessionPool = new HashMap<>();
@OnOpen
public void onOpen(Session session, @PathParam(value = “userId”) Long userId) {
this.session = session;
webSockets.add(this);
sessionPool.put(userId, session);
System.out.println(userId + " 已连接 \n【websocket消息】有新的连接,总数为:" + webSockets.size());
}
@OnClose
public void onClose() {
webSockets.remove(this);
System.out.println(“【websocket消息】连接断开,总数为:” + webSockets.size());
}
@OnMessage
public void onMessage(String message) {
System.out.println(“【websocket消息】收到客户端消息:” + message);
}
/**
- 此为广播消息
*/
public void sendAllMessage(String message) {
fo