java.io.IOException: Service discovery failed

IanMc

Well-Known Member
Licensed User
Longtime User
When you create a virtual serial Com port for bluetooth as an incoming port on the PC you can discover it from your Basic4android app but it would seem that if it is not in use ie: if it is not bound by something like a terminal application then when you try to connect to it you get the error:

java.io.IOException: Service discovery failed

And Amazon reject your app :sign0148:

Is there any way to test for this using Try Catch ?
Then I could display my own error message.

Amazon's helpful rejection email states the error as:

"BTInterfaceFreeTrialBETA Error Connecting: java.io.IOException: read Failed, Socket might closed read ret:-1" appears.


OS/Device(s)/Form Factor: 2.3.3/HTC Desire HD A9191/Phone.
4.2.1/Nexus 7/Tablet.
4.1/Samsung Galaxy Nexus/Phone.
 

IanMc

Well-Known Member
Licensed User
Longtime User
Yes but I've tried putting Try/Catches all over the place and haven't found the right place yet.

It's the same in Erel's Bluetooth Demo app.

If anyone wants to try setting up a Bluetooth serial port on their PC or Laptop then see this thread in my forum.

http://btinterface.com/BTInterface/forum/viewtopic.php?f=2&t=23

It's pretty easy, but if you don't connect the Terminal app up (link provided) then you get that error when you try to connect.

Wonder if we can do anything with the Reflection library?
 
Last edited:
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
More Info

Just in case anyone needs more info on this error
and by 'anyone' I of course mean Erel :D

Here is the output in the log of the error when I uncheck the filter:
B4X:
java.io.IOException: Service discovery failed
   at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:377)
   at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201)
   at anywheresoftware.b4a.objects.Serial$1.run(Serial.java:152)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:444)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
   at java.util.concurrent.FutureTask.run(FutureTask.java:138)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
   at java.lang.Thread.run(Thread.java:1019)

:sign0188:
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
Any thoughts?

Any thoughts on this?

I aim to get it fixed coz I know that anything's possible in B4a!!!

Bye the way, has anyone got themselves a nice well-paid job using B4a yet?

I think its merely a matter of time before B4a starts to get the same kudos as Visual BASIC don't you?

:sign0087:
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Can you identify what command is executed last before you get this exception?
Also does it cause the app to crash or the exception stays silently in the logs?
Is it the Listen or Listen2 command? It seems that the serial library should catch this exception.
If it is the ones of Connect methods, I think the lib still catches the exception but prints the stacktrace silenty (maybe that is what Amazon does not like).
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
You sometimes have to own up to your foolishness

With help from thedesolatesoul on the JonPMs Live b4achat website I figured out... ok 'he' figured out :) that the error message that I'm seing here is

a) written into Erel's Serial1_Connected subroutine :BangHead: Doh!

and the log 'Error Connecting: java.io.Exception: Service discovery failed
' message is

b) written into Erel's Serial1_Connected subroutine :BangHead: Doh!

:D

In my defence I had hidden that routine away deep in the bowels plus I was thrown by that email from the Amazon testing guys which read:

An error message "BTInterfaceFreeTrialBETA Error Connecting: java.io.IOException: read Failed, Socket might closed read ret:-1" appears.


OS/Device(s)/Form Factor: 2.3.3/HTC Desire HD A9191/Phone.
4.2.1/Nexus 7/Tablet.
4.1/Samsung Galaxy Nexus/Phone.

but hands up, I deserve to be entered into the 'lumox of the month' contest

and

no-wonder Erel didn't answer my thread :) he's probably just rolling his eyes and saying to himself

'users'

:sign0104:

now.... no-one reply to this thread... just let it slip gently away into oblivion .... :D

and... take a look at the New error message :)

NewBTErrorMsg.png
 
Last edited:
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi, i had a similar problem. On both devices i change the BT settings : Visible time-out = Never time out. So with this settings i didn't had the error message "java.io.IOException:Service discovery failed"
 

Attachments

  • Screenshot_2013-09-28-23-47-20.png
    Screenshot_2013-09-28-23-47-20.png
    71.1 KB · Views: 440
  • Screenshot_2013-09-28-23-47-53.png
    Screenshot_2013-09-28-23-47-53.png
    70 KB · Views: 387
Upvote 0

gmartano68

New Member
Licensed User
Longtime User
Hi, I get this error while try to test FileTransfer sample via bluetooth (the error occurr when I select the BT device to connect, as in png posted by Andrei) ...any suggestion to solve? I've tried to set Visible time-out = Never on both device, but error remain
 
Upvote 0

Victor Pavlov

Member
Licensed User
Longtime User
Hi,
We created POS system. It supports about 20 printers (Fiscal and ESC/POS). Generally it works, but some times Bluetooth connection crashes with message "java.io.IOException: Service discovery failed"

I was trying different reconnection, delays (idle for 1, 2 or 3 sec), closing and reopening the connection, but no success. Here is full source code, information is sent to first paired device. Please, assist how I can solve the problem. The printout crashes on line 94

Tested with 6 different printers, 3 devices, same result. Crash is about 1/20 of the printouts.
 

Attachments

  • Bluetooth Prototype.zip
    7.1 KB · Views: 303
Upvote 0

Victor Pavlov

Member
Licensed User
Longtime User
Yes, if you see, there is question "Reconnect", after "Yes" it tries to reconnect. But! Sometimes it cannot reconnect after 3 reties (delay = 1 sec). To check it, comment line 95 and it will reconnect and reconnect and reconnect endlessly. Does not solve the problem.

Question, it is paired device, why we need "Discovery service" ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Question, it is paired device, why we need "Discovery service" ?
This is part of the steps required to establish a connection.

Bluetooth in Android is not perfect. You can try to disable and then enable the Bluetooth adapter to reset it. It can be done from your code (like in B4A-Bridge). It usually solves such issues.
 
Upvote 0
Top