joffrey-bion / krossbow

A Kotlin multiplatform coroutine-based STOMP client over websockets, with built-in conversions.
MIT License
189 stars 14 forks source link

Timeout testing on physical devices #500

Closed orelvis15 closed 3 months ago

orelvis15 commented 3 months ago

What happened?

I am doing connection tests from Android TV to a websocket server, when I test from an emulator it works perfectly, but testing from physical devices gives this error.

failed to connect to /192.168.0.77 (port 8080) from /client_ip (port 39416) after 10000ms
Couldn't connect to web socket at ws://hots:port/socket (java.net.SocketTimeoutException: failed to connect to /server_ip (port 8080) from /client_ip (port 39416) after 10000ms)

This is one of the connection tests I have done, which as I mentioned before in an emulator works perfectly, but on physical devices it does not work.

val httpClient = HttpClient(OkHttp) {
        install(WebSockets)
    }
    val wsClient = KtorWebSocketClient(httpClient)

    val stompClient = StompClient(wsClient)
    try {
        stompClient.connect("ws://192.168.0.77:8080/socket")
    }catch (e: Exception){
        Log.d("test", e.message.toString())
        Log.d("test", e.cause?.message.toString())
    }

I was looking for a solution and found this issue in the ktor repository Issue

I tried adding the DNS filter explained in the issue but it still doesn't work

val httpClient = HttpClient(OkHttp) {
        install(WebSockets)
        engine {
            this.config {
                dns(DnsSelector())
            }
        }
    }

class DnsSelector() : Dns {
  override fun lookup(hostname: String): List<InetAddress> {
    return Dns.SYSTEM.lookup(hostname).filter { Inet4Address::class.java.isInstance(it) }
  }
}

The physical device I am testing on is a Rasberry Pi 5 with LinageOS TV ~ Android TV 14.

Reproduction and additional details

No response

Krossbow version

6.0.0

Krossbow modules

krossbow-websocket-ktor, krossbow-websocket-okhttp

Kotlin version

1.9.0

Kotlin target platforms

Android

joffrey-bion commented 3 months ago

Hi Orelvis, thank you for the report.

I see that you mentioned krossbow-websocket-okhttp in the list of modules. Does this mean you reproduced the issue with Krossbow+OkHttp without Ktor, too? If not, could you please try this? Using OkHttp with Krossbow is described here in the docs: https://joffrey-bion.github.io/krossbow/websocket/okhttp/

Also, did you try connecting to the web socket using just the Ktor client (or OkHttp) without Krossbow? If you face the same issue without Krossbow, I'm afraid I won't be able to help, because the issue likely lies in the web socket clients themselves.

orelvis15 commented 3 months ago

Hi @joffrey-bion I did the tests with Krossbow+OkHttp and I had the same result, I just ran the tests only with the ktor client and it is also happening, it seems that it is as you say, it is happening in the clients, I am going to revive the ktor thread where they reported that issue, any solution I find I'll leave here too. Thank you so much!.

joffrey-bion commented 3 months ago

Thanks a lot for the additional tests ❤️ I'll close this issue as invalid (for Krossbow) in the meantime, but feel free to comment further on this with updates/additional info.

Let's hope we get a better resolution out of this from the underlying clients 🙏