代码之家  ›  专栏  ›  技术社区  ›  Rapunzel Van Winkle

附近连接2.0:成功连接,然后立即断开连接

  •  2
  • Rapunzel Van Winkle  · 技术社区  · 9 年前

    P2P_CLUSTER 连接策略,我在让我的设备连接和保持连接方面遇到了问题。根据我的跟踪日志,看起来这些设备正在成功连接,然后立即断开连接。

    以下是我目前看到的一系列事件:

    • 我们发现另一个节点(即,点击onEndpointFound回调),然后发出requestConnection
    • 紧接着,我们击中了onDisconnected(双方都处于未知状态)

    这是一个很大的进步,现在这些设备几乎总是能建立成功(持久)的连接。然而,有时需要2-3次尝试。

    • 我们击中了 onEndpointFound 和 requestConnection
    • 我们击中了 onConnectionInitiated
    • 我们击中了 onConnectionResult 成功连接。
    • onDisconnected
    • 我们停止发现,等待3秒,重新启动发现

    但通过第三次连接过程,我们获得了良好的持久连接,并且能够可靠地发送和接收数据。

    更新:广告客户端的异常导致断开连接?

    10-09 19:17:26.365 29232-29232/? E/SearchServiceStarter: Task 174 failed or timed out. Client 128565203126930423 disconnecting from SearchService!
                                                         java.util.concurrent.CancellationException: Task was cancelled.
                                                             at com.google.common.util.concurrent.d.cp(SourceFile:75)
                                                             at com.google.common.util.concurrent.d.get(SourceFile:57)
                                                             at com.google.common.util.concurrent.cj.n(SourceFile:2)
                                                             at com.google.common.util.concurrent.ay.l(SourceFile:50)
                                                             at com.google.common.util.concurrent.ba.run(SourceFile:5)
                                                             at com.google.android.apps.gsa.shared.util.concurrent.a.bc.run(SourceFile:2)
                                                             at android.os.Handler.handleCallback(Handler.java:808)
                                                             at android.os.Handler.dispatchMessage(Handler.java:103)
                                                             at android.os.Looper.loop(Looper.java:193)
                                                             at android.app.ActivityThread.main(ActivityThread.java:5299)
                                                             at java.lang.reflect.Method.invokeNative(Native Method)
                                                             at java.lang.reflect.Method.invoke(Method.java:515)
                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:831)
                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:647)
                                                             at dalvik.system.NativeStart.main(Native Method)
    

    这有助于您诊断问题吗?

    1 回复  |  直到 9 年前
        1
  •  2
  •   Xlythe    8 年前

    哎呀!这是附近连接中的竞争条件。它将在下一个即将发布的版本中修复。作为一种临时修复方法,将accept连接延迟一小段时间(约100ms?)。

    编辑:这应该从Google Play Services 11.6.0开始修复