Bluetooth Android RFCOMM / SPP error handling suggestions

后端 未结 1 498
遇见更好的自我
遇见更好的自我 2021-01-01 00:07

I am planning a communication protocol to be used between an Android device and a custom sensor that would use a commercial Bluetooth module. I would use the SPP profile tha

相关标签:
1条回答
  • 2021-01-01 00:58

    You need not worry about data corruption over SPP , Bluetooth provides 2 levels of CRC , one at the baseband and then one at the L2CAP level, Both have retransmission mechanism for any detected corruptions - thus applications will receive only good packets.

    About the second question - Yes on the Socket streams that you are connected on you will receive IOExceptions if the underlying Bluetooth connections get disconnected, Android cannot handle automatic restore - typically applications need to detect the reason for disconnection and try re-connect as applicable. So if you want to continue your data exchange from the point you last successfully received / sent then for it your application should maintain some sort of sequence number and light protocol to achieve a resume. The other option is to simply start from the beaning of data exchange upon a re-connect (So it depends on your usecase)

    0 讨论(0)
提交回复
热议问题