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

2

There are 2 answers

1
Menci On BEST ANSWER

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!

6
Markus Junginger On

You need to specify the IP of the machine running the server.

In case you are running an Android emulator, use 10.0.2.2 to reach the host.

This would be a good addition to the Sync troubleshooting guide actually... Updated, thanks.