androidserverconnectionobjectboxobjectbox-android

Objectbox error: "W/Box: [Cl-Lws] LWS: Unable to open socket [Cl-Lws] LWS client connection error: unable to open socket"


I am trying to sync my android application with the sync server, but the client doesn't seem to be able to connect to the server. The Admin UI is running perfectly on localhost:9980. The server is running on docker.

001-13:29:41.2231 [INFO ] [SvrUws] UwsServer listening on all interfaces, port 9999 without SSL
001-13:29:41.2234 [WARN ] [SvSync] UNSECURED no-authentication mode enabled - every client allowed without any validation
001-13:29:41.2256 [INFO ] [SvSync] Started on port 9999
001-13:29:41.2257 [INFO ] [SySvAp] Starting object browser on 0.0.0.0:9980
001-13:29:41.2263 [INFO ] [HttpSv] Running in single-store mode with an already opened store
001-13:29:41.2263 [INFO ] [HttpSv] Listening on 0.0.0.0:9980
001-13:29:41.2266 [WARN ] [HttpSv] UNSECURED no-authentication mode enabled:
!!! Allowing access to anyone without any user validation
!!! After e.g. adjusting user logins, please restart asap to secure the server again
001-13:29:41.2266 [INFO ] [HttpSv] User management: enabled
001-13:29:41.2305 [INFO ] [HttpSv] HttpServer listening on all interfaces, port 9980
001-13:29:41.2318 [INFO ] [SySvAp] ObjectBox sync server started in 62 ms

enter image description here

First I tried what the docs say "wss://127.0.0.1", then I tried with ws, then with the port number specified (both 9980 and 9999). Then I tried to configure the url.

{
    "dbDirectory": "objectbox",
    "bind": "ws://0.0.0.0:9999",
    "browserBind": "http://127.0.0.1:9980",
    "browserThreads": 4,
    "certificatePath": ""
}

None of it worked. Please help me how to find the correct address to connect.

UPDATE: In emulators you have to use 10.0.2.2 to reach localhost! In the MainActivity onCreate() method:

BoxStore boxStore = ObjectBox.get();

        SyncClient syncClient = Sync.client(
                boxStore,
                "ws://10.0.2.2", 
                SyncCredentials.none()
        ).buildAndStart();

enter image description here


Solution

  • SOLVED!

    The android application was missing these permissions:

    <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    

    After adding these, everything worked fine!