Reputation: 1342
I am new to Vert.x, with a goal of building an iot-platform service. The Vert.x ecosystem seems very complete, but I have not found the official advanced usage document about tcpserver data eventbus. Is that necessary to decode and analysis data manually?
The aim is to collect data which is split in specified time or make a window algorithm like other stream data tool? Maybe I am thinking about this in the wrong way, please help me improve this.
Below is my tcpserver code snippet.
@Slf4j
public class TCPServer implements IotGateway {
private Vertx vertx;
private NetServer tcpServer;
@Override
public IotGateway send(String topic, String message) {
return null;
}
public IotGateway start() {
vertx = Vertx.vertx();
// TCP Server
tcpServer = vertx.createNetServer();
tcpServer.connectHandler(socket -> {
System.out.println("TCP client connected");
socket.handler(buffer -> {
System.out.println("Received data from TCP client: " + buffer.toString());
});
socket.closeHandler(v -> {
System.out.println("TCP client disconnected");
});
});
tcpServer.listen(1234, "localhost", ar -> {
if (ar.succeeded()) {
System.out.println("TCP server started");
} else {
System.err.println("Error starting TCP server: " + ar.cause().getMessage());
}
});
return this;
}
}
Upvotes: 0
Views: 19