Is there any recommended approach to make WebSocke...
# multiplatform
a
Is there any recommended approach to make WebSockets work on both Android and iOS, since Ktor WebSockets are still not supported on Kotlin Native?
t
Wanna post the crash from iOS? May just have a bug in their example code
a
Copy code
State CONNECTING
2020-11-20 19:03:43.147439+0100 iOSPlayGround[733:35624] [tcp] tcp_output [C1.1:3] flags=[R.] seq=2675440582, ack=58504070, win=4117 state=CLOSED rcv_nxt=58504070, snd_una=2675440582
2020-11-20 19:03:43.150255+0100 iOSPlayGround[733:35624] Connection 1: received failure notification
2020-11-20 19:03:43.150641+0100 iOSPlayGround[733:35624] Connection 1: failed to connect 3:-9816, reason -1
2020-11-20 19:03:43.150851+0100 iOSPlayGround[733:35624] Connection 1: encountered error(3:-9816)
2020-11-20 19:03:43.157944+0100 iOSPlayGround[733:35624] Task <BD9C63F7-AC4E-4A1D-9B79-2E0190879761>.<1> HTTP load failed, 0/0 bytes (error code: -1200 [3:-9816])
State CLOSED
State CLOSED
State CLOSED
State CLOSED
State CLOSED
and the logs continue with
State CLOSED
insanely down the output
I'm trying to connect to a demo server which is working here: https://www.websocket.org/echo.html
t
Hmmmm yea looks like the cxn never establishes. Not a crash though by the looks of it. The android code to this same server works no issues?
a
Yes, it works on Android. Yeah, it isn't really a crash though. What to do in situations like this, when one target is supported but not the other one? 1. Finding a cocoapod and do the logic in KMM. But the cocoapod needs to written purely in Obj-C for that to work? 2. Kick the iOS websocket logic from KMM and do it natively in the iOS app?
I think these are the available options
t
I'm gonna leave it to someone else to help with that. I'm an iOS dev that hasn't had much of a change to play with Kotlin multiplatform yet - was just hoping I could help unblock you if it was an obvious iOS crash issue.
🙌 2
a
To anyone else who might run into the same issue. The sample code found on the KMM docs website works fine, since the sample WebSocket test server caused the issue on iOS, which can eventually be fixed like described here: https://stackoverflow.com/a/44292653/1974614. However, I didn't find any issues with my own hosted WebSocket production server, so that the example found at the KMM docs website works pretty well on both iOS and Android. No need to wait for Ktor to support it's WebSocket feature on iOS (Kotlin Native). Ktor WebSockets for Android are already there but I don't recommend it since they have a rather weird API to work with.
💯 1