-

0 -

0 -

26 -

4
120 plików
4,74 GB
Ostatnio pobierane pliki
import io.ktor.client.features.websocket.*
import io.ktor.http.cio.websocket.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.net.URI
fun main() = runBlocking {
val client = HttpClient {
install(WebSockets)
}
val clientSession = client.webSocketSession(URI("ws://localhost:8080/echo"))
launch(Dispatchers.IO) {
clientSession.incoming.consumeEach { frame ->
if (frame is Frame.Text) {
println("Received from server: ${frame.readText()}")
}
}
}
clientSession.send(Frame.Text("Hello, Server!"))
// Keep the client running
clientSession.outgoing.send(Frame.Close(CloseReason(CloseReason.Codes.NORMAL, "Client is done")))
client.close()
}
https://blog.stackademic.com/exploring-websockets-in-kotlin-a-comprehensive-guide-with-examples-a9610ad0189d
Nie ma plików w tym folderze
-

0 -

0 -

0 -

0
0 plików
0 KB
Chomikowe rozmowy










Pokaż wszystkie
Pokaż ostatnie
