title: Android client - Java server, Socket won't throw exception
body: <p><br>
  I'm trying to connect my Android APP to a Java server that I've made for it.<br><br>
  I have a problem, the server works good and the APP works fine too when connected to the server. <br><br>
  The problem comes when I close the server and try to connect to it. The suppose is that the <code>Socket.connect()</code> would throw an exception that I would catch, but this exception is not thrown. <br><br>
  I don't know what I'm doing bad, I paste my code here for you to read and maybe somone can help me.<br> Thanks for all mates :D</p>
  
  <p>Connection attributes:</p>
  
  <pre><code>static Socket s;
  static DataOutputStream output;
  static boolean connected;
  </code></pre>
  
  <p>The method who needs the connection:</p>
  
  <pre><code>public void enviarDatos(int r, int g, int b){
  
      connect();
      if(connected){
          panel.setText(panel.getText() + "\nEnviando datos...");
          try {
              output.writeUTF(r + "," + g + "," + b);
          } catch (Exception e) {
              panel.setText("Error: " + e.getMessage());
          }
          disconnect();
      } 
  }
  </code></pre>
  
  <p>The methods to connect and disconnect are there:</p>
  
  <pre><code>public void connect(){
      try {
          s = new Socket();
          int timeout = 1000;
          s.connect(new InetSocketAddress(SERVER_ADDRESS, SERVER_PORT), timeout);
          output = new DataOutputStream(s.getOutputStream());
          connected = true;
          panel.setText("Conexion exitosa.");
  
      } catch (Exception e) {
          connected = false;
          panel.setText("Error: " + e.getMessage());
      }
  }
  
  public void disconnect(){
      try{
          output.close();
          s.close();
          connected = false;
      } catch(Exception e){
          panel.setText("Error: " + e.getMessage());
      }
  }
  </code></pre>