java.net.NoRouteToHostException: No route to host

mc73

Well-Known Member
Licensed User
Longtime User
Hello, I've written a small piece of code for printing to a network printer. During testing, everything worked smoothly except from one point where i received this java error message: 'java.net.NoRouteToHostException: No route to host'.
Now, I know that maybe this has nothing to do with basic4android, still I would prefer to ask for your opinion, since this is the first time I tried to write such code, which goes like this:

sub button_Click
Socket1.Initialize("Socket1")
Socket1.Connect ("printer's ip",port,ms)
end Sub

Sub Socket1_Connected (Successful As Boolean)
If Successful = False Then
Msgbox(LastException.Message, "Error connecting")
Return
End If

Dim sb As StringBuilder
Dim tr2 As TextWriter
Dim s As String

sb.Initialize
sb.Append ("my text and escape codes")

s=sb.ToString
tr2.Initialize2 (Socket1.OutputStream,"my encoding")
tr2.WriteLine (s)
tr2.close

Socket1.Close

end Sub

I wonder if there is something wrong which makes the procedure unstable or it was just a temporary failure of my local network (since this thing happened just once in about 50+ tests), in which case probably I have to asign static IPs to my tablets. Any idea?
 

Kevin

Well-Known Member
Licensed User
Longtime User
I don't know if this will help at all or not but I received this error recently while working on my app.

In my case, my app communicates with a networked satellite receiver. I had rebooted the receiver and attempted to communicate with it before it came back up on the network and I got that same error. I had never seen it before.

My theory was that the router knew of its existence but failed to communicate with it and somehow that is what lead to that error in the B4A app. My reasoning for that is because my app also scans the entire network looking for a response from a receiver by sending a request to every possible IP address. When nothing is there at that address, it fails but with a different error. So to me it seems like that error comes up when the router thinks it should be able to communicate with a device at a specific address but for some reason it can't find it.

Just a theory, but maybe it will help point you to an answer?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Hello,
you are probably right, this is a logical reason!
Anyway, I continued testing and so far everything works properly. So what I am thinking is to simply create a small buffer where I shall save unsent data and try again when such errors appear.
Thank you very much for your reply!
 
Upvote 0
Top