General Bluetooth Data Connections

For RFCOMM connections, the library includes the BluetoothClient, BluetoothAddress, BluetoothEndPoint, and BluetoothListener classes. So, to connect to an RFCOMM/SPP service on a particular peer device, use code like the following. This creates a sockets-like connection which is accessed through a .NET System.IO.Stream for read and write. It does not create a virtual COM port, see Bluetooth Serial Ports for that case.

Class MyConsts
  Shared ReadOnly MyServiceUuid As Guid _
    = New Guid("{00112233-4455-6677-8899-aabbccddeeff}")
End Class

   Dim addr As BluetoothAddress _
     = BluetoothAddress.Parse("001122334455")
   Dim serviceClass As Guid
   serviceClass = BluetoothService.SerialPort
   ' - or - etc
   ' serviceClass = MyConsts.MyServiceUuid
   Dim ep As New BluetoothEndPoint(addr, serviceClass)
   Dim cli As New BluetoothClient
   Dim peerStream As Stream = cli.GetStream()
   peerStream.Write/Read ...

   Dim buf(1000) As Byte
   Dim readLen as Integer = peerStream.Read(buf, 0, buf.Length)
   If readLen = 0 Then
      Console.WriteLine("Connection is closed")
      Console.WriteLine("Recevied {0} bytes", readLen)
   End If
class MyConsts
    static readonly Guid MyServiceUuid
      = new Guid("{00112233-4455-6677-8899-aabbccddeeff}");

    BluetoothAddress addr
      = BluetoothAddress.Parse("001122334455");
    Guid serviceClass;
    serviceClass = BluetoothService.SerialPort;
    // - or - etc
    // serviceClass = MyConsts.MyServiceUuid
    var ep = new BluetoothEndPoint(addr, serviceClass);
    var cli = new BluetoothClient();
    Stream peerStream = cli.GetStream();
    peerStream.Write/Read ...

    byte[] buf = new byte[1000];
    int readLen = peerStream.Read(buf, 0, buf.Length);
    if (readLen == 0) {
        Console.WriteLine("Connection is closed");
    } else {
        Console.WriteLine("Recevied {0} bytes", readLen);
The Service Class Id should be changed to suit the service you are connecting too, e.g. your custom UUID/Guid, BluetoothService.ObexObjectPush, BluetoothService.PhonebookAccessPse, etc. (Do not use BluetoothService.RFCommProtocol that is pointless, BluetoothClient always uses RFCOMM).

A connection can also be made to a particular Port number (RFCOMM Channel number) by setting the port in the BluetoothEndPoint. There are also cases where the service identifies itself not by a unique Service Class Id but by a particular Service Name, for instance when a device has multiple virtual serial port services then the correct one can be identified by its name. In that case see the Connect by Service Name section in the SDP chapter.

Note that RFCOMM/SPP only allows one connection from a remote device to each service. So do not use BluetoothClient and a virtual Serial port to connect to the same service at the same time; the second one will fail to connect. [1]

Note that creating a BluetoothClient or BluetoothListener connection does not create a virtual Serial Port that other applications can use. If you need a virtual COM port for another application to read and write from then see Bluetooth Serial Ports.

DeviceName and Discovery
Bluetooth Server-side
Stream.Read and the Number of Bytes Returned
Connected Property
RFCOMM Control Information


[1] The one RFCOMM connection is a protocol limitation. TCP/IP has port numbers on source and destination ends and thus can support multiple connections, RFCOMM has only the remote channel number so only can support one connection.

If you need multiple connection and are in control of the 'server' device then have the service listen on two (or more) RFCOMM channels so the client can connect to different channel numbers.

Last edited Jan 15, 2014 at 12:17 PM by alanjmcf, version 16


rodrigoelp Oct 1 at 12:52 AM 
I've stumbled across your library as I am trying to find new ways to solve an implementation we have done.

At the moment I have an application that needs to discover a bluetooth device and connect to it without issues, but during usability testing with lots of bluetooth devices around, it was easy to understand our current implementation is not the greatest. Based on that, does 32feet provides a way to determine the proximity of the bluetooth device? I might start creating a sample application for demo purposes in my organisation in which the devices are filtered by a MAC Address (we can identify our devices by the MAC address) to then try to determine the proximity of the device and connect to the one is closest.

nakram Apr 26, 2014 at 9:51 AM 
The UUID you specify in the ServiceClass variable MUST be same on both sides of the connection.

For example, I did this on C# .Net on a Windows 8 laptop with Microsoft BT Stack:

string lgphone = "10:F9:6F:21:2E:2E"; // The MAC address of my phone, lets assume we know it

BluetoothAddress addr = BluetoothAddress.Parse(lgphone);
var btEndpoint = new BluetoothEndPoint(addr, MyConsts.MyServiceUuid);
var btClient = new BluetoothClient();

Stream peerStream = btClient.GetStream();

StreamWriter sw = new StreamWriter(peerStream);
sw.WriteLine("Hello World");

btEndpoint = null;

btServerSock = mBluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord("LGP", java.util.UUID.fromString("00112233-4455-6677-8899-aabbccddeeff"));
btSock = btServerSock.accept();

if(btSock != null){
Log.d(strX, "Null returned");
InputStreamReader isr = new InputStreamReader(btSock.getInputStream());
int charRead = 0;
while((charRead = != -1){
strOut += (char)charRead;
I hope this helps.