All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.firefly.example.kotlin.websocket.WebSocketServerAndClientDemo.kt Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
package com.firefly.example.kotlin.websocket

import com.firefly.kotlin.ext.common.firefly

/**
 * @author Pengtao Qiu
 */
fun main(args: Array) {
    val server = firefly.createWebSocketServer()
    server.webSocket("/helloWebSocket")
        .onConnect { conn -> conn.sendText("OK.") }
        .onText { text, _ -> println("The server received: $text") }
        .listen("localhost", 8080)

    val client = firefly.createWebSocketClient()
    client.webSocket("ws://localhost:8080/helloWebSocket")
        .onText { text, _ -> println("The client received: $text") }
        .connect()
        .thenAccept { conn -> conn.sendText("Hello server.") }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy