Hello everyone, I am trying to implement websocket...
# ktor
k
Hello everyone, I am trying to implement websocket feature with ktor, but I only get 404 for the http://localhost:8080/ request in browser. Could you, please, tell me what can be wrong? Here is my websocket implementation:
Copy code
webSocket("/") {
    while (true) {
        delay(3000)
        outgoing.send(Frame.Text("hi"))
    }
}
r
Hitting that from the browser isn't making a websocket request, it's an http request. They are fundamentally different. You'd have to use a web socket client to make the request there, AFAIK
k
I also tried to use chrome extentions to make that call with ws:// scheme. But it still not found
r
What's your main config look like? Do you have the right port?
k
Copy code
ktor {
    application {
        modules = [com.pinkydev.server.MainAppKt.main]
    }
}
This is the config file
r
But what port is that listening on? If you make an http get handler at / does that work on port 8080?
k
From the console output it runs on localhost:8080/
👍 1
r
Also, I notice you aren't using the incoming receive channel at all in your handler. Perhaps that's the problem? I think this code might just get stuck in q loop since it's not using
for (frame in incoming)
k
I thought it isn’t required to use. I only need output one.🤔
I installed intellij idea and ktor plugin (previously was android studio) and there was some websocket config so it seems to work with this setup, but only with generated client (not in browser)