Nearby Connections 2.0 中的错误代码 [英] Error codes in Nearby Connections 2.0

查看:17
本文介绍了Nearby Connections 2.0 中的错误代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试验新的Android Nearby Connections v2.0 API.我的大多数设备现在大部分时间都可以相互通信,但我也得到了很多 错误代码 尝试连接时返回.在我的程序中检查 status.getStatusCode(),我可以看到以下返回代码:

I've been experimenting with the new Android Nearby Connections v2.0 API. Most of my devices can now talk to each other most of the time, but I also get a lot of error codes back when trying to connect. Checking status.getStatusCode() inside my program, I can see the following return codes:

  • STATUS_ALREADY_CONNECTED_TO_ENDPOINT (8003)
  • STATUS_BLUETOOTH_ERROR (8007)
  • STATUS_ENDPOINT_IO_ERROR (8012)
  • STATUS_ERROR (13)

我很难理解这些.第一个错误代码似乎不言自明,除了在我没有在所谓的连接的任何一侧使用SUCCESS"返回代码点击 onConnectionResult 回调的情况下,我会看到它.我当前的代码充满了跟踪语句,如果达到了这些回调,我会看到日志记录.因此,这些设备可能是在某个较低级别连接的,但如果是这样,则较高级别的代码并不总是会听到.

I'm having a hard time making sense of these. The first error code seems self-explanatory, except that I see it in cases when I haven't hit the onConnectionResult callback with a "SUCCESS" return code on either side of the alleged connection. My current code is full of trace statements, and I'd see logging entries if those callbacks had been reached. So maybe the devices are connected at some lower level, but if so, the higher-level code doesn't always hear about it.

我猜 STATUS_BLUETOOTH_ERROR 表示记录它的一侧出现蓝牙错误,而 STATUS_ENDPOINT_IO_ERROR 表示另一端出现错误(可能涉及蓝牙)?是否有可能获得更多详细信息?我偶尔看到的 STATUS_ERROR (13) 状态听起来像是程序员在那些WTF,我们永远不应该到达这里"时刻使用的那种错误代码,但如果无法访问源代码,我只能猜测.

I'm guessing that STATUS_BLUETOOTH_ERROR indicates a Bluetooth error on the side that logs it, while STATUS_ENDPOINT_IO_ERROR indicates an error (probably involving Bluetooth) on the other end? Is it possible to get any more details? The STATUS_ERROR (13) status that I see once in a while sounds like the sort of error code a programmer would use for those "WTF, we should never get here" moments, but without access to the source code, I can only guess.

请注意,我在使用相同代码的设备之间看到了这些错误,这些设备在其他时候可以很好地相互通信.有时,如果代码重试足够多的次数,它最终会获得稳定的连接.有时它会连接并立即与另一端断开连接.有时,我只会收到源源不断的重复错误消息(STATUS_BLUETOOTH_ERROR 和/或 STATUS_ENDPOINT_IO_ERROR).

Note that I see these errors between devices that talk to each other beautifully at other times, using the same code. Sometimes if the code retries enough times, it eventually gets a stable connection. Sometimes it connects and gets instantly disconnected from the other end. Sometimes I just get an endless stream of repeated error messages (STATUS_BLUETOOTH_ERROR and/or STATUS_ENDPOINT_IO_ERROR).

我将 Nearby Connections 与连接策略 P2P_CLUSTER 一起使用.当双方都做广告和发现时,这些问题似乎最常发生.但是,我编写了两个较小的程序,专门用于广告或发现,它们有时也会出现这些错误(但不太常见).

I'm using Nearby Connections with the connection strategy P2P_CLUSTER. These problems seem to happen most often when both sides do both advertising and discovery. However, I wrote two smaller programs that specialize in either advertising or discovery, and they sometimes get these errors too (but less often).

在跟踪消息中,我还注意到来自 Nearby Connections 的许多警告消息,如下所示:

In the trace messages, I've also noticed lots of warning messages from Nearby Connections that look like this:

09-04 22:54:40.070 3866-3924/? W/NearbyConnections: Cannot deserialize BluetoothDeviceName: expecting min 16 raw bytes, got 6

我猜这是因为 Nearby Connections 使用自己的短令牌(如 ZGbx)而不是设备蓝牙名称?不过,我对此完全不确定.无论如何,如果这些是 Nearby Connections 自己的特殊令牌,那么它为什么会发出有关它的警告消息?

I'm guessing that this is because Nearby Connections uses its own short tokens (like ZGbx) instead of the device Bluetooth name? I'm not at all sure about that, though. And anyway, if these are Nearby Connections' own special tokens, then why would it be issuing warning messages about it?

推荐答案

[免责声明:我在 Nearby Connections 工作] 我可以尝试提供帮助.

[Disclaimer: I work on Nearby Connections] I can try and help out.

STATUS_ALREADY_CONNECTED_TO_ENDPOINT:如果您在与给定端点有任何挂起 (onConnectionInitiated) 或已建立 (onConnectionResult) 连接时调用requestConnection",则会发生这种情况.将您的日志语句提前移至 onConnectionInitiated,您应该会明白我们为什么会抛出此错误.

STATUS_ALREADY_CONNECTED_TO_ENDPOINT: This occurs if you call 'requestConnection' while you have any pending (onConnectionInitiated) or established (onConnectionResult) connections to the given endpoint. Move your log statements earlier, to onConnectionInitiated, and you should see why we throw this error.

STATUS_BLUETOOTH_ERROR:蓝牙出现问题.手机可能处于不良状态.这(希望)不应该经常发生.但如果你真的想要修复,停止广告 &重新尝试 requestConnection 之前的发现.Nearby Connections 会在检测到此错误时切换蓝牙,但前提是没有其他任何事情发生.

STATUS_BLUETOOTH_ERROR: Something went wrong with Bluetooth. The phone is probably in a bad state. This (hopefully) shouldn't happen too often. But if you really want a fix, stop advertising & discovery before reattempting requestConnection. Nearby Connections will toggle Bluetooth when it detects this error, but only if nothing else is going on.

STATUS_ENDPOINT_IO_ERROR:我们失去了与其他设备的连接.发生这种情况的原因有多种(他们可能走得太远、蓝牙不稳定、设备停止响应等).如果您是在有联系的情况下发现的,请避免这种情况.手机上的发现可能很困难,充其量会减少带宽,最坏的情况会导致连接断开.

STATUS_ENDPOINT_IO_ERROR: We lost connection to the other device. This can happen for a variety of reasons (they could have walked too far away, Bluetooth was flaky, the device stopped responding, etc). If you're discovering while you have connections, avoid that. Discovery can be hard on the phone and reduces bandwidth at best, causes dropped connections at worst.

STATUS_ERROR:出现了不适合其他错误代码的错误.这是一个包罗万象的.这通常在 onConnectionResult(FAILED) 中返回,以通知您在 onConnectionInitiated 和等待双方接受连接之间出现问题.

STATUS_ERROR: Something went wrong that didn't fit well in the other error codes. It's a catch-all. This is most-often returned in onConnectionResult(FAILED), to notify you that something went wrong in between onConnectionInitiated and waiting for both sides to accept the connection.

我们还在即将发布的版本中降低了无法反序列化 BluetoothDeviceName"的日志严重性,因为这并不是真正的警告.就像你说的;当我们在发现时看到非 Nearby Connections 设备时的预期行为.

We've also lowered the log severity of "Cannot deserialize BluetoothDeviceName" in an upcoming release, since it's not really a warning. It's like you said; expected behavior when we see non-Nearby Connections devices while discovering.

如果您仍然看到问题,请告诉我们您使用的是什么设备,我们一定会将它们添加到我们的测试套件中.

If you continue to see problems, let us know what devices you're using and we'll be sure to add them to our test suite.

这篇关于Nearby Connections 2.0 中的错误代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆