Why does connect() fail with "no route to host" for Bluetooth sockets on Linux?

308 Views Asked by At

I am learning how to implement Bluetooth communication between two programs in C, for the Linux operating system, using low level socket programming via the basic socket API.

I already have good experience developing servers and clients using sockets in C, as well as Python, and I am fascinated by the similarity with which you can do Bluetooth socket communication as well.

Now, let me give you the reason why I am asking this question. Please forgive me, if anything sounds naive, because I am totally new to Bluetooth programming using sockets.

I understand RFCOMM as well as L2CAP protocols on a very high level. I am trying to develop a very basic server and client application that uses Bluetooth for communication.

I'm following the code from this resource:

https://people.csail.mit.edu/albert/bluez-intro/x502.html

The server is working fine and the accept() call blocks waiting for a new connection to arrive.

Now, things go broke, when I run the client application. I am using the MAC address of my Bluetooth adapter, which I found via running hciconfig -a, as the server's address to connect to. I only have one Bluetooth adapter.

But unfortunately, the connect() system call fails with an error code of 113, or no route to host!

I am totally frustrated & depressed because of this. It seems as if my Bluetooth learning journey has come to a stop! :(

Please do consider my situation and help me in every way possible!

I tried doing the same thing in Python using PyBlueZ, and I get the same error on the client side.

Why is this happening? What does no route to host even mean?

Please understand that I checked my Bluetooth connection, and it has no problems. I can transfer files from Ubuntu to my Android phone, etc.

Please note, that I am using VirtualBox to run Ubuntu on my Windows PC that has built-in Bluetooth support. But whenever Ubuntu uses Bluetooth, Windows seems to magically lose the Bluetooth option itself! I don't know why!

0

There are 0 best solutions below