Android Question B4X B4XPages No route to host

Dave G

Active Member
Licensed User
Trying to add to my Bluetooth prototype and connect to a server that accepts TCP connections.

Attempt to connect to host:
Private Sub ConnectToServer(Host As String)
    Log("Trying to connect to: " & Host)
    CloseExistingConnection
    client.Initialize("client")
    client.Connect(Host, PORT, 10000) ' Host is 192.168.0.233 and PORT is 2008
    Wait For client_Connected (Successful As Boolean)
    If Successful Then
        tcpAStream.InitializePrefix(client.InputStream, False, client.OutputStream, "bluetoothAStream")
        tcpStateChanged (True)
    Else
        Private theEx As Exception = LastException
        Log("Failed to connect: " & theEx.Message)
    End If
End Sub

The Exception.Message is "android.system.ErrnoException: isConnected failed: EHOSTUNREACH (No route to host)"

I can connect to the host/port using Xamarin as well as a TCP ping.

Stumped.
 

DonManfred

Expert
Licensed User
Longtime User
your device is connected to the same network?
 
Upvote 0

Dave G

Active Member
Licensed User
Yes. I even went into the Firewall and made sure the Port and IPs were allowed for TCP. The server is 192.168.0.233 and the client is in the DHCP range of 192.168.0.40-69. BTW, the B4I and B4J test app have the same issue.
 
Upvote 0

Dave G

Active Member
Licensed User
Yes. I have code from a Xamarin app that establishes a TCP connection and the server program shows the Connect and Disconnect (and fails to connect if the server isn't running). I also have an Android utility that uses TCP to Ping and the Pings show as Connects and Disconnects in my server. I even went in to Norton 360 and explicitly Allowed the DHCP IP range and port range of my server apps. I don't know if Windows 10 has anything to do with it. Very strange as I've done TCP-based client server for over 20 years on Unix and Windows.
 
Upvote 0

Dave G

Active Member
Licensed User
Here's a striped down version without the Bluetooth code.
 

Attachments

  • BluetoothPages-TCP-onlyForum.zip
    410.5 KB · Views: 120
Upvote 0

Dave G

Active Member
Licensed User
Thanks. That is the code that I incorporated into my Bluetooth prototype. Obviously I missed something. I'll go through my code and the example line by line. One thing I changed was to not start the client's server since it's not used, but shouldn't have anything to do with it working.
 
Upvote 0

Dave G

Active Member
Licensed User
Yes, but in the process of incorporating it into my prototype I broke something. The relevant lines appear identical. I'm going to take the code from the example and incorporate it as is and then little by little fit it into my Bluetooth prototype. I'll post what it was that became broken.
 
Upvote 0

Dave G

Active Member
Licensed User
OK I took a reverse route and replaced my code with the code from the sample. Then I edited a little and retested etc. At one point it got the same exception so I did a bunch of Undo's and got it working. Then continued to edit until it suited my needs. At first couldn't determine what made it go bad so did some further testing by altering different values. Lo and behold I had introduced the problem by specifying 192.168.0.223 vs 192.168.0.233. I was so fixated on the code that I missed a literal. Sorry for the misdirection. I now know that the No Route to Host can simple mean that the host isn't found because it doesn't exist.
 
Upvote 0
Top