Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Maximum packet size to send data over bluetooth in Android?

I'm working on an Android Bluetooth project to send and receive data from a custom made hardware. I used Bluetooth Chat Sample in SDK as basis.

I am sending data from one device to another (LG Nexus 4). All is ok until I reach a length of 1004 bytes (it is the audio data). At that point it splits it into 2 messages of 990 and 14 bytes in most of cases. but is strange sometimes its sending 1004 without splitting (approx. 4 times in 100).

I am sending this packet of 1004 bytes, in which there is 4 bytes is my header and rest of 1000 bytes is actual data which I want to use as per command in header, now if packets are splitting as per above mentioned way than I cannot handle the flow.

So, please let me know why packets are splitting in such way and how can I stop this splitting or, if I cannot do this, than please suggest me any alternative way to do this.

Thanks.

like image 860
Jignesh Ansodariya Avatar asked Jul 02 '13 06:07

Jignesh Ansodariya


People also ask

How big are Bluetooth packets?

The payload size for the Bluetooth 4.2 link-layer data packet can now go up to 251 bytes, compared to 27 bytes in the older version of Bluetooth specification. Per-packet overhead remains same (i.e., 14 bytes). However, this overhead is now associated with up to 251 bytes instead of 27 bytes.

Can you send data over Bluetooth?

In Devices settings, select Send or receive files via Bluetooth. In Bluetooth File Transfer, select Send files > choose the device you want to share to > Next. Select Browse > the file or files to share > Open > Next (which sends it) > Finish.


1 Answers

Data sent via Bluetooth socket is abstracted as a stream. Here the transport layer is broken into packets, where packet has a maximum size of almost 1KB(1000 bytes). So you can devise a mechanism in which you can send the message length info in the header, then on receiving side you will have to make subsequent read() calls; each returning data for one packet.

like image 178
Bilal Ahmed Avatar answered Nov 15 '22 00:11

Bilal Ahmed