https://kotlinlang.org logo
#ktor
Title
# ktor
p

pardom

07/17/2019, 3:52 PM
Is it possible to mix
websocket
routes and
http
routes? I get a
500
hitting an
http
route when a websocket route is open. I thought it would suspend.
g

gotoOla

07/17/2019, 7:24 PM
@pardom how do you mean? ws and http are two different protocols so one is exposed with ws (or wss) and the other one with http (or https)
p

pardom

07/17/2019, 7:29 PM
I’m configuring the
routing
block with
get
and
webSocket
. The
get
block response correctly until the
webSocket
route is hit, upon which the
get
block returns a
500
. I had assumed that each route would suspend, allowing each route to respond concurrently, it appears that they block each other.
Using the example from https://ktor.io/servers/features/websockets.html, here’s an example:
Copy code
routing {
    get("/hello") {
        call.respond("Hello, World")
    }

    webSocket("/") { // websocketSession
        for (frame in incoming) {
            when (frame) {
                is Frame.Text -> {
                    val text = frame.readText()
                    outgoing.send(Frame.Text("YOU SAID: $text"))
                    if (text.equals("bye", ignoreCase = true)) {
                        close(CloseReason(CloseReason.Codes.NORMAL, "Client said BYE"))
                    }
                }
            }
        }
    }
}
g

gotoOla

07/17/2019, 9:48 PM
hm yes different endpoints should definitely be able to respond in parallel, I had a look in my code and it seems I have never mixed them in the same routing-block though. Do you see anything in the logs when the endpoint returns a 500?
3 Views