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

Sudhanshu Singh

09/28/2023, 6:09 AM
I am opening a websocket
Copy code
val client = HttpClient {
    install(WebSockets) 
}
 client.webSocket( urlString = "<wss://sampleA.com/websocket>") {
        // listen to incoming messages         
 }
Is it possible now to close this websocket and open another one with different url?
Copy code
client.webSocket( urlString = "<wss://sampleB.com/websocket>") {
               
 }
🙂 1
a

Aleksei Tirman [JB]

09/28/2023, 9:00 AM
You can call the
webSocketSession
method to have a control over the session:
Copy code
val client = HttpClient(CIO) {
    install(WebSockets)
}
val session = client.webSocketSession("<wss://ws.postman-echo.com/raw/>")
// Do something with the session
session.send(Frame.Text("hello"))
session.close()
val session2 = client.webSocketSession("<wss://ws.postman-echo.com/raw/>")
s

Sudhanshu Singh

09/28/2023, 9:02 AM
Thanks will try it.