Is it possible to mix `websocket` routes and `http...
# ktor
p
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
@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
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
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?