I have this error on iOS client and I'm not sure h...
# ktor
d
I have this error on iOS client and I'm not sure how to fix it:
Copy code
Error Domain=NSURLErrorDomain Code=-1011 "There was a bad response from the server." UserInfo={NSErrorFailingURLStringKey=<ws://test.com/rpc>, NSErrorFailingURLKey=<ws://test.com/rpc>, _NSURLLErrorWebSocketHandshakeFailureReasonKey=0, NSLocalizedDescription=There was a bad response from the server.}
Thread in Slack Conversation
a
Cc @Aleksei Tirman [JB]
d
Cc @Oleg Yukhnevich I thought to mention you just in case, because I saw you had a similar task https://youtrack.jetbrains.com/issue/KTOR-4085/Multiplatform-Client-Server-SSLTLS-configuration, no fix needed though, just to be in the context There is a different error messages/behavior on Darwin, and a different one on CIO Ktor client when attempting to call a server (web-socket based connection): Darwin client complains: (probably needs to be "wss" instead of "ws", I will test soon)
Copy code
Error Domain=NSURLErrorDomain Code=-1011 "There was a bad response from the server." UserInfo={NSErrorFailingURLStringKey=ws://<test>.com/rpc, NSErrorFailingURLKey=ws://<test>.com/rpc, _NSURLLErrorWebSocketHandshakeFailureReasonKey=0, NSLocalizedDescription=There was a bad response from the server.}
CIO client complains:
TLS sessions are not supported on Native platform.
Maybe the CIO TLS session support will be added after this task will be done
In the end it worked with Darwin Ktor Client!, but :
Copy code
get<HttpClient>().rpc {
    url {
        host = "test.com"
        encodedPath = "/rpc"
        protocol = URLProtocol.WSS //added this line
        port = 0 //added this line
    }
    rpcConfig {
        serialization {
            json()
        }
    }
}
Explicitly set that protocol is URLProtocol.WSS (unless it's not secured) Explicitly set port 0 - this one is weird, DEFAULT_PORT is 0 anyway, but for a reason it transforms to 80, and makes wrong url call in the end: "test.com:80/rpc" however you need "test.com/rpc" *instead of test.com I use a real domain of a real server on hetzner, backed by traefik. On Android (CIO impl.) it will work without these changes out of the box
🔥 1
a
@Dumitru Preguza, can you please share a code snippet with the direct call to
websocket
to reproduce the problem?
d
@Aleksei Tirman [JB] the issue was: • I did not know that CIO ktor client for iOS does not support yet TLS sessions (it’s a known thing) • I did not know that for Darwin client I have to put explicitly the protocol type to WSS (by default it’s WS), because on android the CIO client worked without setting the protocol explicitly • Then the port if you don’t need it, it should set explicitly to 0, otherwise it will be 80, again it worked on Android CIO client without setting WSS and port to 0 explicitly Now I resolved the issues and it works, do you still want to check the behaviours of CIO and Darwin clients on iOS? I could create a repository for you
a
The behavior of the CIO engine is expected and understood. I cannot reproduce the problem when doing an ordinary Websockets call with the Darwin engine. It would be helpful if you could prepare a sample project to reproduce the problem, which requires a workaround to set the
URLProtocol.WSS
protocol explicitly.
👍🏻 1
d
@Aleksei Tirman [JB] I concluded that it's easier to share with you my private pet project, could you please send me your github email in PM ? The project is almost empty anyway, and it does not make sense to copy paste it and deal with build, also the server is deployed and you can reuse the connection from there