Hi all, I'm trying to add a WebSocket Client to ei...
# multiplatform
d
Hi all, I'm trying to add a WebSocket Client to either my jsMain or commonMain code of a Kotlin MPP. I've tried writing my own simple code and also tried using sample code from the chat client example. Every time I try to connect to my server from my JS code running in both Safari and Chrome, the connection attempt sees to just hang and never reach the server. There is no logging from the server route and I never reach the breakpoint at the beginning of the route if I run the server in debug mode. I see a TRACE from KtorSimpleLoggerJs.kt that says
Sending WebSocket request [object Object]
I then see the logging output from the HTTP Client logger:
Copy code
HttpClient: REQUEST: <ws://localhost:8080/story-log/aee6d73d-a6ee-48cb-a614-30424501fda7/50256788-5ca0-4776-b65e-08679e93ad48>
METHOD: HttpMethod(value=GET)
COMMON HEADERS
-> Accept: */*
-> Accept-Charset: UTF-8
CONTENT HEADERS
-> Connection: upgrade
-> Sec-WebSocket-Key: MzRhYzYzNDNiNzIzMjY1ZA==
-> Sec-WebSocket-Version: 13
-> Upgrade: websocket
BODY Content-Type: null
BODY START
Copy code
BODY END
Sometimes (minutes later), I'll get an error (from
JsClientEngine.kt:75
) saying:
Copy code
HttpClient: REQUEST <ws://localhost:8080/story-log/aee6d73d-a6ee-48cb-a614-30424501fda7/50256788-5ca0-4776-b65e-08679e93ad48> failed with exception: WebSocketException: {"target":{},"type":"error","isTrusted":true}
When I try the same request from PostMan, the connection is successful. Anyone have any idea what I'm doing wrong here?