|
@@ -48,6 +48,7 @@ public class ChatServer {
|
48
|
48
|
* 连接建立成功调用的方法*/
|
49
|
49
|
@OnOpen
|
50
|
50
|
public void onOpen(Session session,@PathParam("sid") String sid) {
|
|
51
|
+ removeSameFromSets(sid);
|
51
|
52
|
this.session = session;
|
52
|
53
|
webSocketSet.add(this);
|
53
|
54
|
addOnlineCount();
|
|
@@ -61,7 +62,6 @@ public class ChatServer {
|
61
|
62
|
@OnClose
|
62
|
63
|
public void onClose() {
|
63
|
64
|
removeFromSets();
|
64
|
|
- log.info("有一连接关闭!当前在线人数为" + getOnlineCount());
|
65
|
65
|
}
|
66
|
66
|
|
67
|
67
|
/**
|
|
@@ -120,6 +120,17 @@ public class ChatServer {
|
120
|
120
|
if (sid.equals(c.sid)) {
|
121
|
121
|
webSocketSet.remove(c);
|
122
|
122
|
subOnlineCount();
|
|
123
|
+ log.info("有一连接关闭:"+sid+"!当前在线人数为" + getOnlineCount());
|
|
124
|
+ }
|
|
125
|
+ }
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ private void removeSameFromSets(String currentSid) {
|
|
129
|
+ for(ChatServer c: webSocketSet) {
|
|
130
|
+ if (currentSid.equals(c.sid)) {
|
|
131
|
+ webSocketSet.remove(c);
|
|
132
|
+ subOnlineCount();
|
|
133
|
+ log.info("有一连接关闭:"+sid+"!当前在线人数为" + getOnlineCount());
|
123
|
134
|
}
|
124
|
135
|
}
|
125
|
136
|
}
|