Skip to content

Instantly share code, notes, and snippets.

@league55
Created October 16, 2019 14:23
Show Gist options
  • Save league55/eca704f1a37083cc1631a95f3b64c80d to your computer and use it in GitHub Desktop.
Save league55/eca704f1a37083cc1631a95f3b64c80d to your computer and use it in GitHub Desktop.
public class ServerConnection implements ConnectionService {
private Vertx vertx;
public ServerConnection(Vertx vertx) {
this.vertx = vertx;
}
@Override
public boolean enable(Connection configuration) {
vertx.createNetServer().connectHandler(socket -> onConnect(configuration, socket))
.listen(configuration.getPort(), configuration.getHost());
return configuration.isEnabled();
}
private Handler<Buffer> onConnect(Connection configuration, NetSocket socket) {
return buffer -> {
configuration.getProviderService().getInfo(buffer.getString(0, buffer.length())).compose(s -> {
socket.write(s);
socket.write("\r\n");
return Future.succeededFuture();
});
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment