title: Exception Connection refused while connecting Android device to PC
body: <p>This i the code of Connection </p>
  
  <pre><code>  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      DL_URL = "http://localhost:8080/project-server/rest/?value=test";
      downloadJsonFile();
  
  }
  
   private void downloadJsonFile() {
          try {
              createFileAndDirectory();
              URL url = new URL(DL_URL);
              HttpURLConnection urlConnection;
              urlConnection = (HttpURLConnection) url.openConnection();
              urlConnection.setRequestMethod("GET");
              urlConnection.setDoOutput(true);
              urlConnection.connect();
  
  
              int status = urlConnection.getResponseCode();
  
              Log.v("gg", Integer.toString(status));
              if (status == HttpURLConnection.HTTP_OK) {
              FileOutputStream fileOutput = new FileOutputStream(jsonFile);
              InputStream inputStream = urlConnection.getInputStream();
              byte[] buffer = new byte[1024];
              int bufferLength = 0;
              while ((bufferLength = inputStream.read(buffer)) &gt; 0) {
              fileOutput.write(buffer, 0, bufferLength);
              }
              fileOutput.close();
              }else{
                   Toast.makeText(MainActivity.this,"error :)", Toast.LENGTH_LONG).show();
  
          }} catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          }
  </code></pre>
  
  <p>And this is my servles located @my own PC tha I try to connect to it (I use Windows 7)</p>
  
  <pre><code>   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      doPost(request, response);
  }
  
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
   }
  </code></pre>
  
  <p>Erros I get </p>
  
  <pre><code>    06-18 12:42:55.940: W/System.err(4740): java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused
      06-18 12:42:55.950: W/System.err(4740):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207)
      06-18 12:42:55.950: W/System.err(4740):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
      06-18 12:42:55.950: W/System.err(4740):     at java.net.Socket.connect(Socket.java:983)
      06-18 12:42:55.950: W/System.err(4740):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.&lt;init&gt;(HttpConnection.java:75)
      06-18 12:42:55.950: W/System.err(4740):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.&lt;init&gt;(HttpConnection.java:48)
      06-18 12:42:55.950: W/System.err(4740):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
      06-18 12:42:55.950: W/System.err(4740):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
      06-18 12:42:55.950: W/System.err(4740):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
      06-18 12:42:55.950: W/System.err(4740):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
      06-18 12:42:55.950: W/System.err(4740):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
      06-18 12:42:55.950: W/System.err(4740):     at com.example.test1.MainActivity.downloadJsonFile(MainActivity.java:42)
      06-18 12:42:55.950: W/System.err(4740):     at com.example.test1.MainActivity.onCreate(MainActivity.java:30)
      06-18 12:42:55.950: W/System.err(4740):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
      06-18 12:42:55.950: W/System.err(4740):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
      06-18 12:42:55.950: W/System.err(4740):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
      06-18 12:42:55.950: W/System.err(4740):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
      06-18 12:42:55.950: W/System.err(4740):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
      06-18 12:42:55.950: W/System.err(4740):     at android.os.Handler.dispatchMessage(Handler.java:99)
      06-18 12:42:55.950: W/System.err(4740):     at android.os.Looper.loop(Looper.java:130)
      06-18 12:42:55.950: W/System.err(4740):     at android.app.ActivityThread.main(ActivityThread.java:3835)
      06-18 12:42:55.950: W/System.err(4740):     at java.lang.reflect.Method.invokeNative(Native Method)
      06-18 12:42:55.950: W/System.err(4740):     at java.lang.reflect.Method.invoke(Method.java:507)
      06-18 12:42:55.950: W/System.err(4740):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
      06-18 12:42:55.950: W/System.err(4740):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
      06-18 12:42:55.960: W/System.err(4740):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>