我想为Android创建离线多人游戏,所以我需要在设备之间进行可靠的p2p通信。谷歌附近的连接工作相当不错,但我发现了一个问题。设置为标准 - 设备A通告,设备D发现并连接到A.然后D断开连接,再次发现再连接。在一到十次迭代之后,D仍然可以连接到A并从A接收数据,但它不能再发送数据。我用sendPayload
拨打Payload.fromBytes
,收到onSuccessCallback
,但A没有收到此有效负载。稍后D接收onPayloadTransferUpdate
状态代码2.进一步重新连接并不能解决问题。只有能够可靠地解决问题的是重启。
一些日志:
03-21 12:20:25.827 30317-30317/com.alienff.ntest I/Log: [21.03.2018 12:20:25.827] [main] MainActivity: sending payload -5864147190526311071
03-21 12:20:25.841 30317-30317/com.alienff.ntest I/Log: [21.03.2018 12:20:25.841] [main] MainActivity: payload cent
...
03-21 12:21:16.925 3066-3215/? D/WifiStateMachine: Current network is: "___mm___
" , ID is: 0
03-21 12:21:16.926 3066-3215/? D/WifiStateMachine: Current network is still qualified due to heavy traffic, txSuccessRate=2.1973258256066233 rxSuccessRate=0.0
03-21 12:21:16.926 3066-3215/? D/WifiStateMachine: Current network is 5GHz, bail out...
03-21 12:21:17.408 4049-4049/? D/io_stats: !@ 179,0 r 906136 23065676 w 370340 7270584 d 46705 2438912 f 147311 147270 iot 680350 657112 th 51200 0 0 pt 0 inp 0 0 55938.769
03-21 12:21:17.571 10176-30596/? W/NearbyConnections: Unexpected call to physicalConnectionClosed() for medium WIFI_LAN while NearbyRecorder has active medium BLUETOOTH -- metadata{ service_id: 0 }
03-21 12:21:17.576 10176-30596/? W/NearbyConnections: Unexpected call to physicalConnectionClosed() for medium WIFI_LAN with no corresponding EstablishedConnection that was previously opened. -- metadata{ service_id: 0 }
03-21 12:21:17.579 10176-30596/? W/NearbyConnections: NearbyRecorder expected no more active physical connections before logging this endpoint connection. -- metadata{ service_id: 0 }
03-21 12:21:17.585 3336-3929/? E/BluetoothRemoteDevices: setRfcommConnected false
03-21 12:21:17.586 30317-30317/com.alienff.ntest I/Log: [21.03.2018 12:21:17.586] [main] MainActivity: onPayloadTransferUpdate. endpointId: 7oRz payloadId: -5864147190526311071 bytesTransferred: 0 status: 2
03-21 12:21:17.597 30317-30317/com.alienff.ntest I/Log: [21.03.2018 12:21:17.596] [main] MainActivity: onDisconnected: 7oRz
您知道如何让谷歌附近的连接可靠地重新连接吗? 谢谢!
答案 0 :(得分:0)
我以前没见过这个,所以我打算让你为我做一些调试。
当前的想法: 状态代码2是" PayloadTransferUpdate.Status.FAILURE"。通常会立即断开连接,因为套接字被假定为断开。但是,套接字看起来并不坏。您仍在接收数据,并且在内部,我们在连接时通过套接字发送一连串控制消息,这些消息都已成功完成,或者您无法获得onConnectionResult。这意味着Payload本身出现问题;无论是在你身边,还是我们的。我怀疑你发送了FILE或STREAM有效负载,因为我不知道BYTE有效负载可能出现故障的方式。如果文件已移动或ParcelFileDescriptor变为无效,则FILE有效负载可能会失败。如果关闭socket或ParceFileDescriptor或者收集垃圾,则STREAM有效负载可能会失败。
免责声明:我致力于附近连接