Hello, I'm trying to create a web socket connectio...
# ktor
m
Hello, I'm trying to create a web socket connection in a KMP project as follows but it's giving me this exception:
Serializer for class 'DefaultClientWebSocketSession' is not found
Copy code
Caused by: kotlinx.serialization.SerializationException: Serializer for class 'DefaultClientWebSocketSession' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
Copy code
class WebSocketClientImpl(engine: HttpClientEngine) : WebSocketClient() {

    private val client = HttpClient(engine) {
        install(ContentNegotiation) {
            register(
                ContentType.Text.Html, KotlinxSerializationConverter(
                    Json
                )
            )
        }
        install(WebSockets) {
            contentConverter = KotlinxWebsocketSerializationConverter(Json)
        }
    }

    private var session: WebSocketSession? = null

    override fun getWebSocketEvents(): Flow<List<String>> = flow {
        session = client.webSocketSession {
            url {
                takeFrom("<wss://sl-socket-receive.eu.ngrok.io>")
            }
        }
        session!!.incoming
            .consumeAsFlow()
            .filterIsInstance<Frame.Text>()
        //emitAll(data)
    }

    override suspend fun close() {
        session?.close()
        session = null
    }
}
I have tried multiple things but I'm not able to figure out what's wrong.
a
If you remove the
register
call in the
ContentNegotiation
plugin, the problem disappears?
m
No, it'll give me another error as the response content-Type is
text/html
a
What is the response from the server?