Switched from text to binary messages.
parent
b29a3128bd
commit
baf413a063
|
@ -56,7 +56,7 @@ public class ClientPeriodicStdinScanner implements Handler<Long> {
|
|||
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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<ServerWebSocket> {
|
||||
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<String> {
|
||||
static class WebsocketMessageHandler implements Handler<Buffer> {
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue