Created
October 16, 2019 14:23
-
-
Save league55/eca704f1a37083cc1631a95f3b64c80d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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