diff --git a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/ClientPeriodicStdinScanner.java b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/ClientPeriodicStdinScanner.java index aa19daa..d49a565 100644 --- a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/ClientPeriodicStdinScanner.java +++ b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/ClientPeriodicStdinScanner.java @@ -56,7 +56,7 @@ public class ClientPeriodicStdinScanner implements Handler { Buffer b = Buffer.buffer(len); b = b.appendBytes(clientPayload, prevIdx, len); b = b.appendByte((byte)'\n'); - webSocket.writeTextMessage(b.toString(StandardCharsets.UTF_8)); + webSocket.writeBinaryMessage(b); prevIdx = idx + eolLength; } } while (idx >= 0 && prevIdx < clientPayload.length); diff --git a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientParticle.java b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientParticle.java index 1dd2583..2ddc0a4 100644 --- a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientParticle.java +++ b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/client/WebsocketClientParticle.java @@ -56,7 +56,7 @@ public class WebsocketClientParticle extends AbstractVerticle { )); webSocket - .textMessageHandler(msg -> logger.info("Got message: {}", msg)) + .binaryMessageHandler(msg -> logger.info("Got message: {}", msg)) .closeHandler(unused -> { try { stop(); diff --git a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/server/WebsocketServerHandler.java b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/server/WebsocketServerHandler.java index 6a21e19..75c952c 100644 --- a/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/server/WebsocketServerHandler.java +++ b/2024/08/chat_demo1/chat_demo1_web/src/main/java/ch/polgrabia/demos/server/WebsocketServerHandler.java @@ -2,31 +2,33 @@ package ch.polgrabia.demos.server; import ch.polgrabia.demos.client.WebsocketClientApp; import io.vertx.core.Handler; +import io.vertx.core.buffer.Buffer; import io.vertx.core.http.ServerWebSocket; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class WebsocketServerHandler implements Handler { - private static final Logger logger = LoggerFactory.getLogger(WebsocketClientApp.class); + private static final Logger logger = LoggerFactory.getLogger(WebsocketServerHandler.class); @Override public void handle(ServerWebSocket serverWebSocket) { - serverWebSocket.writeTextMessage("Hello"); - serverWebSocket.textMessageHandler(new WebsocketTextMessageHandler(serverWebSocket)); + serverWebSocket.writeBinaryMessage(Buffer.buffer("Hello")); + serverWebSocket.handler(new WebsocketMessageHandler(serverWebSocket)); } - static class WebsocketTextMessageHandler implements Handler { + static class WebsocketMessageHandler implements Handler { private final ServerWebSocket serverWebSocket; - public WebsocketTextMessageHandler(ServerWebSocket serverWebSocket) { + public WebsocketMessageHandler(ServerWebSocket serverWebSocket) { this.serverWebSocket = serverWebSocket; + this.serverWebSocket.setWriteQueueMaxSize(0); } @Override - public void handle(String s) { + public void handle(Buffer s) { logger.info("Got message {}", s); - serverWebSocket.writeTextMessage("Pong: " + s); // TBD send to kafka + serverWebSocket.writeBinaryMessage(Buffer.buffer("Pong: " + s.toString() + "\n")); // TBD send to kafka } }