@@ -53,24 +53,19 @@ public void onError(WebSocketSession session, Throwable error) {
5353 error .printStackTrace ();
5454 }
5555
56- /**
57- * Echo: 받은 메시지를 그대로 반환
58- */
5956 @ MessageMapping ("/echo" )
6057 public void handleEcho (WebSocketSession session , @ Payload String message ) throws IOException {
6158 totalMessagesReceived ++;
6259 session .sendText (createResponse ("/echo" , message ));
60+ System .out .println ("[WebSocket Benchmark] Echo: " + message );
6361 totalMessagesSent ++;
6462 }
6563
66- /**
67- * Broadcast: 모든 연결된 클라이언트에 메시지 전송
68- */
6964 @ MessageMapping ("/broadcast" )
7065 public void handleBroadcast (WebSocketSession session , @ Payload String message ) throws IOException {
7166 totalMessagesReceived ++;
7267 String response = createResponse ("/broadcast" , "From " + session .getId () + ": " + message );
73-
68+ System . out . println ( "[WebSocket Benchmark] Broadcast: " + message );
7469 for (WebSocketSession s : sessions .values ()) {
7570 if (s .isOpen ()) {
7671 try {
@@ -83,9 +78,6 @@ public void handleBroadcast(WebSocketSession session, @Payload String message) t
8378 }
8479 }
8580
86- /**
87- * Chat: 채팅 메시지 처리
88- */
8981 @ MessageMapping ("/chat" )
9082 public void handleChat (WebSocketSession session , @ Payload String message ) throws IOException {
9183 totalMessagesReceived ++;
@@ -96,6 +88,7 @@ public void handleChat(WebSocketSession session, @Payload String message) throws
9688 }
9789
9890 String chatMessage = username + ": " + message ;
91+ System .out .println ("[WebSocket Benchmark] Chat: " + chatMessage );
9992 String response = createResponse ("/chat" , chatMessage );
10093
10194 // 채팅방의 모든 사용자에게 전송
@@ -111,21 +104,18 @@ public void handleChat(WebSocketSession session, @Payload String message) throws
111104 }
112105 }
113106
114- /**
115- * Ping-Pong: 간단한 응답
116- */
117107 @ MessageMapping ("/ping" )
118- public void handlePing (WebSocketSession session , String message ) throws IOException {
108+ public void handlePing (WebSocketSession session , @ Payload String message ) throws IOException {
119109 totalMessagesReceived ++;
120- session .sendText (createResponse ("/pong" , "pong" ));
110+ // 실제 WebSocket Ping 프레임 전송 (브라우저가 자동으로 Pong 응답)
111+ byte [] pingData = "ping" .getBytes ();
112+ session .sendPing (pingData );
113+ System .out .println ("[WebSocket Benchmark] Sent Ping frame to client: " + session .getId ());
121114 totalMessagesSent ++;
122115 }
123116
124- /**
125- * Stats: 통계 정보 반환
126- */
127117 @ MessageMapping ("/stats" )
128- public void handleStats (WebSocketSession session , String message ) throws IOException {
118+ public void handleStats (WebSocketSession session , @ Payload String message ) throws IOException {
129119 totalMessagesReceived ++;
130120 String stats = String .format (
131121 "연결: %d, 수신: %d, 송신: %d, 누적 연결: %d" ,
@@ -135,18 +125,12 @@ public void handleStats(WebSocketSession session, String message) throws IOExcep
135125 totalMessagesSent ++;
136126 }
137127
138- /**
139- * JSON 응답 메시지 생성
140- */
141128 private String createResponse (String destination , String payload ) {
142129 // JSON 형식: {"destination": "...", "payload": "..."}
143130 return String .format ("{\" destination\" :\" %s\" ,\" payload\" :\" %s\" }" ,
144131 destination , escapeJson (payload ));
145132 }
146133
147- /**
148- * JSON 문자열 이스케이프
149- */
150134 private String escapeJson (String str ) {
151135 if (str == null ) return "" ;
152136 return str .replace ("\\ " , "\\ \\ " )
@@ -156,14 +140,12 @@ private String escapeJson(String str) {
156140 .replace ("\t " , "\\ t" );
157141 }
158142
159- // 통계 초기화 (테스트용)
160143 public static void resetStats () {
161144 totalMessagesReceived = 0 ;
162145 totalMessagesSent = 0 ;
163146 totalConnections = 0 ;
164147 }
165148
166- // 통계 조회 (테스트용)
167149 public static String getStats () {
168150 return String .format (
169151 "Sessions: %d, Received: %d, Sent: %d, Total Connections: %d" ,
0 commit comments