title: Transfer data from one device to another - android
body: <p>so I have created two separate apps, one acts as a client &amp; the other acts as a server. Both devices are connected using hotspot:</p>
  
  <p>Connection between the devices is successful. For transferring data from the server to the client, I am using the below code: </p>
  
  <pre><code>    public static String downloadDataFromSender(String apiUrl) throws IOException {
      InputStream is = null;
      try {
          URL url = new URL(apiUrl);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.setReadTimeout(10000 /* milliseconds */);
          conn.setConnectTimeout(15000 /* milliseconds */);
          conn.setRequestMethod("GET");
          conn.setDoInput(true);
  
          /* Starts the query  */
          conn.connect();
          conn.getResponseCode();
  
          is = conn.getInputStream();
  
          /* Convert the InputStream into a string  */
          return readIt(is);
      } finally {
          if (is != null) {
              is.close();
          }
      }
  }
  </code></pre>
  
  <p>But I keep getting the following error:</p>
  
  <pre><code>java.net.SocketTimeoutException: connect timed out
  at java.net.PlainSocketImpl.socketConnect(Native Method)
  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:343)
  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:205)
  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:187)
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
  at java.net.Socket.connect(Socket.java:586)
  at com.android.okhttp.internal.Platform.connectSocket(Platform.java:113)
  at com.android.okhttp.Connection.connectSocket(Connection.java:196)
  at com.android.okhttp.Connection.connect(Connection.java:172)
  at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
  at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
  at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
  at com.wifiscanner.utils.DownloadUtils.downloadDataFromSender(DownloadUtils.java:27)
  at com.wifiscanner.tasks.SenderAPITask.doInBackground(SenderAPITask.java:29)
  at com.wifiscanner.tasks.SenderAPITask.doInBackground(SenderAPITask.java:14)
  at android.os.AsyncTask$2.call(AsyncTask.java:304)
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
  at java.lang.Thread.run(Thread.java:761)
  </code></pre>
  
  <p>The url I am using in the download is this:<a href="http://192.168.43.1:52287/files" rel="nofollow noreferrer">http://192.168.43.1:52287/files</a></p>
  
  <p>The connection is successful as I said. So not sure why I am getting network is unreachable. This happens intermittently and not always. </p>
  
  <p>Could someone provide some detail on why this is happening?</p>