• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Problem with socket code, always fails to connect to Bluetooth device

Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the error:

E/DEMO_APP: Socket connection failed on device
   java.io.IOException: read failed, socket might closed or timeout, read ret: -1
       at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:925)
       at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:939)
       at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:494)
       at com.hudngo.android.BluetoothService$ConnectedThread.run(BluetoothService.java:120)

The android phone is paired with the bluetooth device, I see it when scanning paired devices, I connect to the device I want based on Mac address and the device object I pass is correct. But the connection always fails, I want to have my android mobile app connect and be able to receive messages from the bluetooth device so it can execute code on the mobile app based on actions done on the bluetooth device. I've tried many things and the connection always fails. I sampled code off the android developer docs.

I also tried using my car as a test bluetooth device since the phone is paired, connects to it, and I should be able to read in data from the car but that fails too trying to use both client / server socket code, accept() ends up stalling then failing as well when trying the other way: tmp2 = Bluetooth.bluetoothAdapter.listenUsingRfcommWithServiceRecord("testing", mmUUID); and my car gives me a uuid to read in and use..so must be my connection code if nothing is working even with a real working bt device.

Service class

Main activity call
Posts: 478
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi  is that the whole error?  Also why are you directly using threads.
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
Enterprise-grade Excel API for Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!