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

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

我正在尝试将我的 android 应用程序与同步服务器同步,但客户端似乎无法连接到服务器。管理员 UI 运行 完全 localhost:9980。 服务器在 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

首先我尝试了文档所说的“wss://127.0.0.1”,然后我尝试了 ws,然后是指定的端口号(9980 和 9999)。 然后我尝试配置 url.

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

None 有效。请帮助我如何找到正确的连接地址。

更新: 在模拟器中,您必须使用 10.0.2.2 才能到达本地主机! 在 MainActivity 的 onCreate() 方法中:

BoxStore boxStore = ObjectBox.get();

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

你需要指定机器的IP运行服务器

如果您是 运行 一个 Android 模拟器,请使用 10.0.2.2 访问主机。

这将是对 Sync troubleshooting guide 的一个很好的补充实际上...已更新,谢谢。

已解决!

android 应用程序缺少这些权限:

<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" />

添加这些后,一切正常!