2

So I have an android application that communicate with a server through Socket. It was working yesterday at a point. In the evening I wanted to work more on it but it throws a exception without me modifying the code at all. After remaking the project 2 times I tested the connection with an app that I know that works 100% because I tried it few days ago.

After researching my problem on web I found out that it might be due to a malware software i installed yesterday. I uninstalled it but it still doesn't work.

I ll not post any code here because it isn't relevant. (as i said i tried with something that should work but it doesn't)

java.net.ConnectException: failed to connect to /(my ip is here) (port 2225): connect failed: EHOSTUNREACH (No route to host)
                                                                    at libcore.io.IoBridge.connect(IoBridge.java:124)
                                                                    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
                                                                    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:163)
                                                                    at java.net.Socket.startupSocket(Socket.java:592)
                                                                    at java.net.Socket.<init>(Socket.java:226)
                                                                    at com.shoppiness.radu.jshoppiness.Client.run(Client.java:63)
                                                                    at com.shoppiness.radu.jshoppiness.MainActivity$connectTask.doInBackground(MainActivity.java:77)
                                                                    at com.shoppiness.radu.jshoppiness.MainActivity$connectTask.doInBackground(MainActivity.java:61)
                                                                    at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                                    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                    at java.lang.Thread.run(Thread.java:818)
                                                                 Caused by: android.system.ErrnoException: connect failed: EHOSTUNREACH (No route to host)
                                                                    at libcore.io.Posix.connect(Native Method)
                                                                    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
                                                                    at libcore.io.IoBridge.connectErrno(IoBridge.java:137)
                                                                    at libcore.io.IoBridge.connect(IoBridge.java:122)
                                                                    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183) 
                                                                    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:163) 
                                                                    at java.net.Socket.startupSocket(Socket.java:592) 
                                                                    at java.net.Socket.<init>(Socket.java:226) 
                                                                    at com.shoppiness.radu.jshoppiness.Client.run(Client.java:63) 
                                                                    at com.shoppiness.radu.jshoppiness.MainActivity$connectTask.doInBackground(MainActivity.java:77) 
                                                                    at com.shoppiness.radu.jshoppiness.MainActivity$connectTask.doInBackground(MainActivity.java:61) 
                                                                    at android.os.AsyncTask$2.call(AsyncTask.java:295) 
                                                                    at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                                                                    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                                    at java.lang.Thread.run(Thread.java:818) 
Radu
  • 128
  • 1
  • 15
  • Please refer this:https://stackoverflow.com/questions/12522396/tcp-ip-client-ehostunreach-no-route-to-host –  Aug 29 '17 at 18:51

3 Answers3

0

If you are using a lan server make sure both devices (android and server) are on the same wifi.

Your firewall might be blocking the connection to.

  • Server is supposed to recieve message from android devices all around the country. I tried to connect it on mobile data then on local wi fi but both do not work. – Radu Aug 30 '17 at 14:01
0

So if you are hosting the server, make sure you portforwarded the wifi the server is running on. That will allow trafic to go through your router and to server.

-1

This is probably just because your device is not connectd to the internet. Connect it to wifi and try again. Good luck