```fun main() = runBlocking { val httpClient ...
# coroutines
s
Copy code
fun main() = runBlocking {

    val httpClient = HttpClient {
        install(Logging) {
            level = LogLevel.ALL
        }

        @OptIn(KtorExperimentalAPI::class)
        install(WebSockets)

        expectSuccess = false

        install(JsonFeature) {
            @OptIn(KtorExperimentalAPI::class)
            acceptContentTypes = listOf(ContentType("application", "json-rpc"))
            serializer = KotlinxSerializer()
        }
    }
    val wss =httpClient.webSocketSession(method = HttpMethod.Get, host = "127.0.0.1", port = 6800, path = "/jsonrpc")
    wss.close()
}
this does not stop the program. what am I doing wrong?
message has been deleted
shouldn't it just stop the program after
wss.close()
?
s
wws.close()
closes the websocket. If you want to cancel the coroutine to stop the program then you could use
main.cancel()
👀 1
s
I mean, I am not asking
wss.close
to close the coruotune. What I want is that the main finishes which doesn't if I use this wss snippet. If I replace all wss code with just
println, then main finishes
j
Are you sure it's actually connecting at all? The API documentation is practically non-existent, but I think the call to
websocketSession
suspends until the connection is established, and so
main
wouldn't finish until it does
b
you need to close httpClient as well 🙂
Also, instead of doing
fun main() = runBlocking{}
you can do
suspend fun main() {}
s
thats the fix i needed. thanks. Also, was
suspend mani
recent feature?
b
I've discovered it a month or so ago. No idea when it was actually introduced.
a
wait what? main suspend functions are a thing?