0

I'm doing bluetooth socket programming, and I have few questions about sockets provided by BlueZ.

When we're dealing with TCP/IP socket programming, we can usually choose either TCP or UDP as our transport protocol. As far as I know, these two protocols are mutual exclusive (we can only choose one of them).

However, I found that BlueZ provided both L2CAP and RFCOMM sockets for us. For example, in pybluez, we can choose either bluetooth.L2CAP or bluetooth.RFCOMM as an argument to construct a socket.

import bluetooth

server_sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM ) # or bluetooth.L2CAP

My question is: Aren't L2CAP and RFCOMM perform different functions and at different levels in the bluetooth stack? In other words, I guess both of them are indispensable, then how could we possibly only choose one of them as a protocol to construct a socket?

Did I misunderstand something? Or it's just that the socket specified in the code just determines the entry position of the socket in the bluetooth stack, with both L2CAP and RFCOMM still functioning? If that is the case, why is BlueZ providing two different socket entries for us?

I have read through the introduction here: https://people.csail.mit.edu/albert/bluez-intro/x95.html, and I know that with L2CAP or RFCOMM specified, we can have different settings, like the number of ports. But I still cannot get which protocols to use and why they exist.

I'm new to Bluetooth, and I will appreciate any of your help very much! Thank you!

KaiwenJon
  • 1
  • 1
  • This website (SO) is for coding questions. The answer to your question is already available [here.](https://stackoverflow.com/questions/20868038/bluetooth-protocol-rfcomm-l2cap-and-acl). – Mr. Panda Jul 24 '21 at 15:49
  • Does this answer your question? [Bluetooth protocol (RFCOMM, L2CAP and ACL)](https://stackoverflow.com/questions/20868038/bluetooth-protocol-rfcomm-l2cap-and-acl) – Mr. Panda Jul 24 '21 at 15:49
  • @Mr.Panda Oh.. sorry.. I wasn't aware of that. Thank you for reminding me! And...! The link you provide seems to be the one I'm looking for! I cannot thank you more...! – KaiwenJon Jul 24 '21 at 16:03
  • I just went through contents in [Bluetooth protocol (RFCOMM, L2CAP and ACL)](https://stackoverflow.com/questions/20868038/bluetooth-protocol-rfcomm-l2cap-and-acl). And I may answer to myself: It seems that BlueZ just encapsulated RFCOMM and L2CAP layers, and we can construct sockets at different entries in the bluetooth stack, so that we won't need to handle anything in the upper layers. – KaiwenJon Jul 24 '21 at 16:14

0 Answers0