title: Send a string to wifi connected device return the EHOSTUNREACH (No route to host) in android
body: <p>So , the  flow of the application is  , </p>
  
  <p>first , I use my android phone to connect a device (which is a server) through wifi, then , I would like to send a string to that device, and that is all.</p>
  
  <p>The problem is , when I try to send like this</p>
  
  <pre><code>new Thread(new Runnable() {
      @Override
      public void run() {
          try {
  
              Socket socket = new Socket("192.168.8.101",2001);
              DataOutputStream DOS = new DataOutputStream(socket.getOutputStream());
              DOS.writeUTF("61");
              socket.close();
  
          } catch (Exception e) {    
              final String error = e.getMessage();
              runOnUiThread(new Runnable(){
  
                  @Override
                  public void run() {
                      Toast.makeText(mContext, error, Toast.LENGTH_SHORT).show();
                  }
  
              });
  
              Log.d("test1",e.getMessage());
              e.printStackTrace();
          }
  
  }).start();
  </code></pre>
  
  <p>it return the failed to connect to <code>/192.168.8.101 (port 2001) : connect failed EHOSTUNREACH (No route to host)</code> in the  exception</p>
  
  <p>How to fix that , and by programming or using some way , are there any way to check whether the ip and port is correct ? Thanks</p>