I am facing the same issue...i tried calling ClientSocket.close(), but it 
didn't help in my case. The connection fails for android 4.0.4 verizon 
galaxy tab with 4.1.2 Nexus S phone.

I am calling createRfCommSocket first and then trying to connect, but every 
time it fails, doesn't matter how many loops i do. Even restart of Tab 
doesn't help.


Please help.

On Monday, December 28, 2009 7:13:28 AM UTC-8, Brad Hein wrote:
>
>
> I'm developing an application that interfaces with an RFCOMM endpoint.
> Through bluetooth, my Droid phone connects to this device, initializes
> it, and happily sends and receives data.
>
> A problem I have encountered however is when I walk away from the
> device (while it's sending/receiving) and the bluetooth connection
> goes stale. I easily detect this in my code by various exceptions
> thrown by the inputstream/outputstream/socket. When this happens, I
> immediately "disconnect" from the endpoint by doing the following:
>
> try {
>   if (instream != null ) instream.close();
>   if (outstream != null ) outstream.close();
>   if (mobdSock != null ) mobdSock.close(); // this is the socket.
> } catch... etc.
>
> So after performing the above steps to officially "disconnect" the
> dead connection I thought the connection is clean and ready for a new
> connect()...
>
> But what happens is when I come back into range of the device and try
> to connect, I am unable to reconnect, no matter how many times I try.
> connect() throws this exception: java.io.IOException: Device or
> resource busy
>
> The only way I can then reconnect to the device is to disable
> bluetooth on my droid, then re-enable it. Then my app is able to re-
> connect just fine.
>
> BluetoothDevice -> BluetoothAdapter -> BluetoothSocket -> InputStream/
> OutputStream.
>
> I'm currently tearing down the connect from the socket to the right
> (see above). Should I be tearing it down all the way down to the
> adapter instead? or the device? By setting those to null so GC can
> clean them up? This is the best idea I can come up with but it doesn't
> feel right.
>
> Thanks
> Brad
>
>

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to