Search code examples
c#androidbluetoothandroid-bluetoothnetworkstream

BluetoothClient(C#) write delayed while reading from Android client


I am trying to write the continuous data from bluetoothclient(C# NetworkStream) to Android client (BluetoothSocket). But I observed that C# write is getting blocked , while trying to read data from Android bluetooth socket.This block is not observed if I am not trying to read data from client. Tried using BufferedStream for writing , but still I see the same issue.

C# Bluetooth server Code :

NetworkStream _st = _clnt.GetStream();
while(true){
   _st.Write(_serData, 0, _serData.Length);
   // Required delay is given before writing next chunk
}

Android Bluetooth reader :

InputStream inputstream = btSocket.getInputStream()
while(true){
 int len = inputstream.read(buffer, offset, buffer.length);
 offset += len;
}

Solution

  • Solved this issue by sending keep-ALive packets from ANdroid client side , solved my problem as suggested in

    Application using bluetooth SPP profile not working after update from Android 4.2 to Android 4.3