Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebSocket support for the iOS #1894

Closed
Hixie opened this issue May 25, 2020 · 19 comments
Closed

Add WebSocket support for the iOS #1894

Hixie opened this issue May 25, 2020 · 19 comments
Assignees

Comments

@Hixie
Copy link

Hixie commented May 25, 2020

Ktor Version and Engine Used (client or server and name)
Using io.ktor:ktor-client-ios:1.3.2

Describe the bug
This code prints kotlin.IllegalStateException: [generateNonce] is not supported on iOS:

  GlobalScope.launch {
    try {
      HttpClient {
        install(WebSockets)
      }.wss(
        host = "websocketstest.com",
        path = "/service"
      ) {
        send(Frame.Text("timer"))
        for (frame in incoming)
          println((frame as Frame.Text).readText())
      }
    } catch (e: Exception) {
      println(e)
    }
  }

Looks like someone tried to fix this here: #1535

@Hixie Hixie added the bug label May 25, 2020
@e5l
Copy link
Member

e5l commented May 26, 2020

Hi @Hixie, the WebSocket is unsupported on the iOS for now.

@e5l e5l added feature and removed bug labels May 26, 2020
@e5l e5l self-assigned this May 26, 2020
@omainegra
Copy link

Hello, any update on this? I notice there's a PR that got stale #1535

@omainegra
Copy link

I tried to use that code and it worked up to the point where I got another error

io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteChannelNative -> class io.ktor.client.features.websocket.DefaultClientWebSocketSession
with response from wss://javascript.info/article/websocket/chat/ws:
status: 101 Switching Protocols
response headers: 
CF-Cache-Status: DYNAMIC
, Server: cloudflare
, CF-RAY: 5a042751df0be0fa-IAD
, Upgrade: websocket
, cf-request-id: 033676e7230000e0fa31210200000001
, Sec-WebSocket-Accept: Dx6gENctpo2lUPMOWA1N7wLwcfE=
, Date: Mon, 08 Jun 2020 16:57:44 GMT
, alt-svc: h3-27=":443"; ma=86400
, Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
, Connection: upgrade

        at 0   iosApp                              0x0000000107ad340e kfun:kotlin.Throwable.<init>()kotlin.Throwable + 62
        at 1   iosApp                              0x0000000107ac5f87 kfun:kotlin.Exception.<init>()kotlin.Exception + 55
        at 2   iosApp                              0x0000000107ac61a7 kfun:kotlin.RuntimeException.<init>()kotlin.RuntimeException + 55
        at 3   iosApp                              0x0000000107ac6a07 kfun:kotlin.UnsupportedOperationException.<init>()kotlin.UnsupportedOperationException + 55
        at 4   iosApp                              0x0000000108721576 kfun:io.ktor.client.call.NoTransformationFoundException.<init>(io.ktor.client.statement.HttpResponse;kotlin.reflect.KClass<#STAR>;kotlin.reflect.KClass<#STAR>)io.ktor.client.call.NoTransformationFoundException + 678
        at 5   iosApp                              0x000000010871e997 kfun:io.ktor.client.call.HttpClientCall.$receiveCOROUTINE$5.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? + 2775
        at 6   iosApp                              0x000000010871ed80 kfun:io.ktor.client.call.HttpClientCall.receive(io.ktor.client.call.TypeInfo)kotlin.Any + 320
        at 7   iosApp                              0x000000010877a621 kfun:io.ktor.client.features.websocket.$webSocketCOROUTINE$49.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? + 5729
        at 8   iosApp                              0x0000000107aff568 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 712
        at 9   iosApp                              0x000000010864a8a6 kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal + 950
        at 10  iosApp                              0x000000010864a45a kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1658
        at 11  iosApp                              0x000000010864c5f9 kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal + 377
        at 12  iosApp                              0x0000000107aff849 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1449
        at 13  iosApp                              0x000000010864a8a6 kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal + 950
        at 14  iosApp                              0x000000010864a45a kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1658
        at 15  iosApp                              0x000000010864c5f9 kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal + 377
        at 16  iosApp                              0x0000000107aff849 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1449
        at 17  iosApp                              0x000000010864a8a6 kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal + 950
        at 18  iosApp                              0x000000010864a45a kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1658
        at 19  iosApp                              0x000000010864c5f9 kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal + 377
        at 20  iosApp                              0x0000000107aff849 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1449
        at 21  iosApp                              0x000000010864a8a6 kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal + 950
        at 22  iosApp                              0x000000010864a45a kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1658
        at 23  iosApp                              0x000000010864c5f9 kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal + 377
        at 24  iosApp                              0x0000000107aff849 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1449
        at 25  iosApp                              0x000000010864a8a6 kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal + 950
        at 26  iosApp                              0x000000010864a45a kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal + 1658
        at 27  iosApp                              0x000000010864c5f9 kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal + 377
        at 28  iosApp                              0x0000000107aff849 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 1449
        at 29  iosApp                              0x0000000108460cc3 kfun:kotlinx.coroutines.DispatchedTask.run() + 2627

@e5l
Copy link
Member

e5l commented Jun 8, 2020

Hi @Hixie, the fix is in the master for the nonce class, but there is no WebSocket support for ktor-ios.

@e5l e5l changed the title WebSocket APIs crash on iOS (generateNonce is not supported on iOS) Add WebSocket support for the iOS Jun 8, 2020
@omainegra
Copy link

Hi @e5l, Yes you're right, I noticed it after reading the code, even tho the nonce fix is needed, and the PR looks good, any reason to not merge it?. For the WebSocket support, is possible to modify IosClientEngine to use NSURLSessionWebSocketTask for upgrade request, or be able to use CIO client in MPP (Not possible right now since it uses java classes directly). What should be the best approach?

@e5l e5l added the triaged label Jun 15, 2020
@esdudnik
Copy link

esdudnik commented Jun 15, 2020

@e5l so latest ktor 1.3.2 still don't have websocket implementation on the IOS?

@e5l
Copy link
Member

e5l commented Jun 15, 2020

Yep. We're waiting for native multithreaded coroutines support

@markrebhan
Copy link

Looks like native multithreaded support almost here :)

Kotlin/kotlinx.coroutines#462 (comment)

@ESchouten
Copy link

ESchouten commented Jul 1, 2020

Weirdly, I am getting this exception (kotlin.IllegalStateException: [generateNonce] is not supported on iOS) using io.ktor:ktor-client-curl:1.3.2-1.4-M2, running on linux

Digging into Kotlin Native code, I guess POSIX in general is not supported

@oleg-larshin
Copy link

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

@ln-12
Copy link

ln-12 commented Jan 20, 2021

@e5l Hey, any updates on this?

@AK-Inspify
Copy link

AK-Inspify commented Jan 25, 2021

@e5l yes, please update, we are so excited about websocket support for iOS!

@AlexanderKudinov
Copy link

AlexanderKudinov commented Jun 27, 2021

Hi! Any news? Websocket support for iOS (namely for KMM) is really very necessary. Looking forward!

@MinmoTech
Copy link

Sorry for making this kind of comment, but is there an update on this? :)

@Stexxe
Copy link
Contributor

Stexxe commented May 28, 2022

This feature (KTOR-4093) is already implemented.

@Stexxe Stexxe closed this as completed May 28, 2022
@theromis
Copy link

@Stexxe do you know wss destiny? is it implemented too?
Is this PR related to it's implementation if it still not implemented? #2939

@theromis
Copy link

@Stexxe any progress on TLS for websocket?

@ln-12
Copy link

ln-12 commented Nov 19, 2022

@theromis Why don't you just try it out? There already is a wss builder (see here) and I am using it for quite some time now in my Android and iOS app.

@theromis
Copy link

@ln-12 Thank you, will try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests