ask help for bluetooth buffer reading

icefairy333

Active Member
Licensed User
Longtime User
at first I have an external device used to listening connection from other devices for example an android phone with bluetooth (spp protocol),when connected ,It send 64 packets to other side (begin with 0xff,0xff) and one packet of second type data begin with 0xff,0xfe,per second;
and then ,in b4a I have test two kinds of method ,1,use a timer interval 1ms when begin reading set its enable=false,when reading end set its enable=true;2,use asyncstream object,but in this way,the data received event got a buffer with random length for example 6byte,12byte,18byte,24byte,30byte and so on
so the question is:how many bytes should reading per times?when I read 12 bytes the buffer will accumulate many data as time goes by will more and more,when I read 1024bytes per times,there is no data accumulate,but I can't distinguish the packet is which kind .
any idea?thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should use AsyncStreams. Using a timer will not help as messages can may still be split or merged.

You can use a buffer (List?) to accumulate the bytes and when there are enough bytes you should handle the message. Prefix mode will do all of these for you, however you cannot use it in your case (as you don't control the other side).
 
Upvote 0
Top