5

When I'm running my app through Google Nexus by connecting through USB and trying to connect webservice running on my laptop then I'm getting below error but I'm able to connect to webservie. Please advice.

     java.net.ConnectException: failed to connect to /192.168.1.122 (port 8080):       
           connect failed: ENETUNREACH (Network is unreachable)

            at libcore.io.IoBridge.connect(IoBridge.java:114)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
            at java.net.Socket.startupSocket(Socket.java:566)
            at java.net.Socket.tryAllAddresses(Socket.java:127)
            at java.net.Socket.<init>(Socket.java:177)
            at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
            at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
            at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
            at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
            at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
            at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
            at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83
Sam
  • 244
  • 2
  • 5
  • 20
  • 1
    Error says that the host machine is unreachable , mean that system is not in the network to connect :)Connect laptop into the Network and start trying it should work fine :) ping the ip from the local system topo check the sytem – thar45 Feb 12 '13 at 06:17
  • 2
    This isn't really programming related; your device *isn't on the network* – Brian Roach Feb 12 '13 at 06:23
  • yes as @BrianRoach mentioned you seems not to have connectivity,might help others with the same error, keeping it open. – TheWhiteRabbit Feb 12 '13 at 06:40
  • Or that the receiving port is not open and ready. – Kingsolmn Oct 27 '13 at 20:15

2 Answers2

2

Just because you connect the phone to the computer don't mean that it will create a network connection.

Create a LAN run the web-service on the LAN IP. and use wifi to connect to it.

Thihara
  • 7,031
  • 2
  • 29
  • 56
  • Do I need to enable USB tethering? I'm running my app on tablet but I do not see USB tethering option in tablet. If yes, then how do I enable it? Do I need to download tethering enable app from Google play? – Sam Feb 13 '13 at 01:44
  • When you tether the device to the PC it DOESN'T connect it to the network. It connects it to that particular computer. Please understand that Network is an entirely different thing. – Thihara Feb 13 '13 at 01:50
  • My laptop and tablet are both connected to same wireless network but still unable to access from tablet. Can you please let me know how what needs to be done? – Sam Feb 13 '13 at 02:01
0

You need to publish the services to a location where your phone can connect to them via the Wireless Lan. The USB is only for debugging purposes

Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95