diff --git a/backend/src/main/java/io/metersphere/websocket/c/to/c/IndexWebSocket.java b/backend/src/main/java/io/metersphere/websocket/c/to/c/IndexWebSocket.java index 143a9cb9b8..62593bbd11 100644 --- a/backend/src/main/java/io/metersphere/websocket/c/to/c/IndexWebSocket.java +++ b/backend/src/main/java/io/metersphere/websocket/c/to/c/IndexWebSocket.java @@ -21,8 +21,7 @@ public class IndexWebSocket { @OnOpen public void openSession(@PathParam("reportId") String reportId, Session session) { WebSocketUtils.ONLINE_USER_SESSIONS.put(reportId, session); - log.info("客户端: [" + reportId + "] : 连接成功!"); - //WebSocketUtils.sendMessageAll("客户端: [" + reportId + "] : 连接成功!"); + log.info("客户端: [" + reportId + "] : 连接成功!" + WebSocketUtils.ONLINE_USER_SESSIONS.size()); } /** @@ -43,9 +42,8 @@ public class IndexWebSocket { public void onClose(@PathParam("reportId") String reportId, Session session) throws IOException { //当前的Session 移除 WebSocketUtils.ONLINE_USER_SESSIONS.remove(reportId); - log.info("[" + reportId + "] : 断开连接!"); + log.info("[" + reportId + "] : 断开连接!" + WebSocketUtils.ONLINE_USER_SESSIONS.size()); //并且通知其他人当前用户已经断开连接了 - //WebSocketUtils.sendMessageAll("[" + reportId + "] : 断开连接!"); session.close(); } diff --git a/backend/src/main/java/io/metersphere/websocket/c/to/c/MsWebSocketClient.java b/backend/src/main/java/io/metersphere/websocket/c/to/c/MsWebSocketClient.java index b7f31a57d0..1c73159ad4 100644 --- a/backend/src/main/java/io/metersphere/websocket/c/to/c/MsWebSocketClient.java +++ b/backend/src/main/java/io/metersphere/websocket/c/to/c/MsWebSocketClient.java @@ -1,8 +1,6 @@ package io.metersphere.websocket.c.to.c; -import com.alibaba.fastjson.JSON; import io.metersphere.commons.utils.LogUtil; -import io.metersphere.websocket.c.to.c.util.MsgDto; import org.java_websocket.client.WebSocketClient; import org.java_websocket.handshake.ServerHandshake; @@ -10,23 +8,23 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Iterator; -public class MsWebSocketClient extends WebSocketClient{ +public class MsWebSocketClient extends WebSocketClient { public MsWebSocketClient(String url) throws URISyntaxException { super(new URI(url)); } @Override public void onOpen(ServerHandshake shake) { - System.out.println("握手..."); - for(Iterator it=shake.iterateHttpFields();it.hasNext();) { + LogUtil.info("握手..."); + for (Iterator it = shake.iterateHttpFields(); it.hasNext(); ) { String key = it.next(); - System.out.println(key+":"+shake.getFieldValue(key)); + System.out.println(key + ":" + shake.getFieldValue(key)); } } @Override public void onMessage(String paramString) { - System.out.println("接收到消息:"+paramString); + System.out.println("接收到消息:" + paramString); } @Override @@ -36,6 +34,6 @@ public class MsWebSocketClient extends WebSocketClient{ @Override public void onError(Exception e) { - System.out.println("异常"+e); + System.out.println("异常" + e); } }