The test driver doesn't get blocked: numOfAvailable is always zero. I bet if I remove the instream.available() check. I would get the same exception as the one writing to output stream.
Pluggin a debugger onto the remote device, I found the connection immediately gets disconnected by my android test driver regardless read or write from the subsequent calls. ... one custom feature on the remote device: after connecton being made, it would request a role switch. On other phones, if the local device/phone doesn't support role switch, the connection simply remains without role switching. Just wondering why the connection gets connected but immediately dropped ... On Tue, Nov 24, 2009 at 4:18 PM, Nick Pelly <[email protected]> wrote: > At first glance, the problem is probably that instream.read() will block > until it has 512 bytes. Are you sending enough bytes? > > If you did not intend to send 512 bytes (i cant tell without your server > code), you should use pass numOfAvailable into instream.read(), and it > should return straight away. > > Nick > > > > On Tue, Nov 24, 2009 at 1:22 PM, Sean Liao <[email protected]> wrote: > >> got another error from writing. wondering if this might be related. >> >> 11-24 13:07:27.731: ERROR/BluetoothEventLoop.cpp(1015): event_filter: >> Received signal org.bluez.Device:PropertyChanged from >> /org/bluez/1973/hci0/dev_00_08_1B_CA_C7_29 >> 11-24 13:07:28.606: VERBOSE/BluetoothEventRedirector(1138): Received >> android.bleutooth.device.action.UUID >> 11-24 13:07:30.015: DEBUG/(2254): getOutputStream >> 11-24 13:07:30.052: ERROR/(2254): bt write failed >> *11-24 13:07:30.052: ERROR/(2254): java.io.IOException: Transport >> endpoint is not connected* >> >> I connected an debugger into remote device, and found the Android/My test >> driver initiated an disconnect immediately after connect. >> >> Really appreciate if you can point out what is wrong with my test driver. >> >> Sean >> >> >> >> >> >> On Tue, Nov 24, 2009 at 12:45 PM, Sean Liao <[email protected]>wrote: >> >>> Hi, I wrote a simple test driver to test the bluetooth apis. Anyone can >>> verify whether I am using the API correctly? Everything seems good but no >>> data read :-( >>> >>> >>> >>> >>> =========================================================================== >>> // before calling the following, inquiry scan successfully returned, and >>> the remote device is pre-paired. >>> >>> private boolean doTestConnection() { >>> >>> Log.d("SwxBtCommImpl", "doTestConnection"); >>> >>> String btAddr = "00:08:1B:CA:C7:29"; >>> >>> BluetoothDevice btdev = >>> BluetoothAdapterImpl.getInstance().getRemoteDevice(btAddr); >>> >>> // widcom using the following GUID >>> // 00001101-0000-1000-8000-00805F9B34FB >>> UUID uuid = >>> UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); >>> >>> try { >>> BluetoothSocket btsocket = >>> btdev.createRfcommSocketToServiceRecord(uuid); >>> >>> btsocket.connect(); >>> Log.d("SwxBtCommImpl", "connected"); >>> >>> try { >>> Thread.sleep(1000); >>> } catch (InterruptedException e1) { >>> // TODO Auto-generated catch block >>> e1.printStackTrace(); >>> } >>> >>> InputStream instream = btsocket.getInputStream(); >>> Log.d("", "getInputStream"); >>> >>> byte[] data = new byte[512]; >>> for (int i = 0; i < 20; i++) { >>> int numOfAvailable = instream.available(); >>> >>> Log.d("SwxBtCommImpl", "read " + i + ": " + numOfAvailable + >>> " bytes"); >>> if(numOfAvailable > 0) { >>> int numOfRead = instream.read(data); >>> Log.d("SwxBtCommImpl", new String(data) + "-" + >>> numOfRead); >>> } else { >>> >>> try { >>> Thread.sleep(500); >>> } catch (InterruptedException e) { >>> // TODO Auto-generated catch block >>> e.printStackTrace(); >>> } >>> } >>> } >>> >>> instream.close(); >>> instream = null; >>> >>> btsocket.close(); >>> >>> } catch (IOException e) { >>> // TODO Auto-generated catch block >>> Log.e("", "bt connection failed", e); >>> } >>> >>> >>> >>> return true; >>> } >>> >>> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected]<android-developers%[email protected]> >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

