-
Hello guys. I can not find any example how to work with the WebSocketClient. Here is my implementation:
But it does not work. Or works not correctly. First of all when a connection opens i don't receive the onOpen event. And also when a connection closes i don't receive the onClose event. I am 100% sure that my server works correctly. Because my JavaScript implementation of the WebSocket works fine. I am using the 3.1.0 version of KorGE. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Can you try with 3.4.0 that is the latest version, just in case it was fixed already? Are you trying in the JS target, right? |
Beta Was this translation helpful? Give feedback.
-
The thing is that once connected, the program continues, and it finishes when reaching the end even if there are pending connections. If you don't have an event loop, you should wait until a condition triggers. You could do for example: suspend fun main() {
val closed = Signal<Unit>()
val ws = WebSocketClient("ws://localhost:8000/ws") {
onOpen.add { println("onOpen") }
onError.add { println("onError") }
onStringMessage.add { println("onStringMessage") }
onClose.add { println("onClose"); closed() }
}
closed.waitOne()
// while (true) delay(1.seconds) // alternatively we can wait forever
} |
Beta Was this translation helpful? Give feedback.
The thing is that once connected, the program continues, and it finishes when reaching the end even if there are pending connections. If you don't have an event loop, you should wait until a condition triggers.
You could do for example: