Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 378a512

Browse files
committed
websocketのデモでclientから切断された場合に対処
1 parent c021f25 commit 378a512

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/java/com/secureskytech/demochatasync/PlainWsDemoHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ public Receive createReceive() {
116116
return receiveBuilder().match(Tick0.class, tick -> {
117117
count++;
118118
log.info("tick {}/{}", count, numOfCount);
119+
if (!session.isOpen()) {
120+
log.info("websocket session closed from client.");
121+
session.close(CloseStatus.NORMAL);
122+
getContext().stop(getSelf());
123+
return;
124+
}
119125
try {
120126
// カウンタがerrvalに到達したら、div by zero を発生させる。
121127
if (errval == count) {
@@ -125,6 +131,7 @@ public Receive createReceive() {
125131
log.info("div/zero => stop");
126132
session.close(CloseStatus.SERVER_ERROR);
127133
getContext().stop(getSelf());
134+
return;
128135
}
129136
if (count >= numOfCount) {
130137
log.info("tick count max => stop");

0 commit comments

Comments
 (0)