humuyu 3 rokov pred
rodič
commit
71f9de9355

+ 13 - 12
eladmin-system/src/main/java/me/zhengjie/base/websocket/AppSocketServer.java

@@ -24,23 +24,24 @@ public class AppSocketServer {
 	private String sname = "";
 
 	public AppSocketServer() {
-		// com.gangquan360.smartadmin.module.employee.EmployeeController.query dd;
+
 	}
 
 	@OnOpen
 	public void onOpen(Session session, @PathParam("sname") String sname) {
-
-		this.session = session;
-		// 如果存在就先删除一个,防止重复推送消息
-		for (AppSocketServer webSocket : webSocketSet) {
-			if (webSocket.sname.equals(sname)) {
-				webSocketSet.remove(webSocket);
-			}
-		}
-		webSocketSet.add(this);
-		log.info("有新窗口开始监听:" + sname + "当前人数:" + webSocketSet.size());
-		this.sname = sname;
 		try {
+			this.session = session;
+			// 如果存在就先删除一个,防止重复推送消息
+			for (AppSocketServer webSocket : webSocketSet) {
+				if (webSocket.sname.equals(sname)) {
+					// 发送一个关闭消息
+					webSocket.sendMessage("close");
+					webSocketSet.remove(webSocket);
+				}
+			}
+			webSocketSet.add(this);
+			log.info("有新窗口开始监听:" + sname + "当前人数:" + webSocketSet.size());
+			this.sname = sname;
 			sendMessage("连接成功");
 		} catch (IOException e) {
 			log.error("websocket IO异常:" + e.getMessage());