Android app SocketTimeoutException after 300000ms when smartwatch is not connected via usb cable to PC

Viewed 269

I have an app on smartwatch (Wear OS) which is listening for events on server-sent events endpoint running on my local PC. Smartwatch and PC are on the same network (subnet is the same). I can access the service from my mobile phone browser, which is on the same network. The app is able to connect to end-point when the smartwatch is connected via USB cable to the PC in debug mode, but once I detach it from the cable no events arrived caused by SocketTimeoutException. I tried to increase the timeout, but with no luck. I keep getting this kind of exception. The strange thing is what actually the smartwatch IP wlan is 192.168.1.116 but when it is disconnected from the USB it seems to be changed to 192.168.167.239, the port number is changing with every log printout. the service is on nodejs, using server-sent events. The firewall is disabled. The WLAN connection is private. OS Windows 10. I use the OKhttp3 library to establish the connection.

OkHttpClient client = new OkHttpClient.Builder()
           .proxy(Proxy.NO_PROXY)
            .connectTimeout(30, TimeUnit.SECONDS)
            .readTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(30,TimeUnit.SECONDS)
            .retryOnConnectionFailure(true)
            .build();
    Request.Builder builder = new Request.Builder()
            .url(url)
            .addHeader("Accept-Encoding","identity")
            .addHeader("Accept", "text/event-stream");

java.net.SocketTimeoutException: failed to connect to /192.168.1.109 (port 8081) from /192.168.167.239 (port 55586) after 300000ms: the end-point is 192.168.1.109:8081

Please help me!

1 Answers

It is likely that these are distinct networks, and that you can't connect between them. Perhaps try a service like https://ngrok.com/ to give you a public address to try to connect to.

Related