Created
December 6, 2017 07:40
-
-
Save usmansaleem/dea6deeea6bec3d66141f0a5d106f86d to your computer and use it in GitHub Desktop.
Vertx NetClient Example in Kotlin
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
package info.usmans.blog.example | |
import io.vertx.core.AbstractVerticle | |
import io.vertx.core.Vertx | |
import io.vertx.core.net.NetClientOptions | |
fun main(args: Array<String>) { | |
Vertx.vertx().deployVerticle(NetClientExample()) | |
println("Running NetClientExample!") | |
} | |
/** | |
* A Vertx Verticle to connect to our custom websocket | |
*/ | |
class NetClientExample : AbstractVerticle() { | |
override fun start() { | |
var options = NetClientOptions().apply { | |
isSsl = true | |
} | |
val client = vertx.createNetClient(options) | |
client.connect(8888, "localhost", { event -> | |
if(event.succeeded()) { | |
println("Connected") | |
val socket = event.result() | |
//send pass phrase ... | |
socket.write(System.getProperty("password")) | |
socket.handler({ data -> | |
println("Data received: ${data}") | |
//TODO: Do the work here ... | |
}) | |
socket.closeHandler({ | |
println("Socket closed") | |
//TODO: Attempt to reconnect? or give up | |
}) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment