title: Creating new socket after closing an old one causes connection refused
body: <p>I'm new to android programming and I'm trying to port a program from standard java to android. This java application contains sockets. When I ported the program I get a connection refused if I press a button too fast. I made a simple program for testing.</p>
  
  <pre><code>Thread thread = new Thread(new Runnable() {
      @Override
      public void run() {
          try {
              Socket mySocket = new Socket();
              InetSocketAddress address = new InetSocketAddress("10.94.35.24", 5000);
              mySocket.connect(address, 5000);
              mySocket.shutdownOutput();
              mySocket.shutdownInput();
              mySocket.close();
              Log.w("Socket", "Socket closed");
              Socket mySocket2 = new Socket();
              mySocket2.connect(address, 5000);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  });
  thread.start();
  </code></pre>
  
  <p>I have a server up and running on this IP and port and my program works fine on a java application on my computer. But on android the program gets the following exception when trying to connect to mySocket2</p>
  
  <blockquote>
    <p>java.net.ConnectException: failed to connect to /10.94.35.24 (port
    5000) after 5000ms: isConnected failed: ECONNREFUSED (Connection
    refused)</p>
  </blockquote>
  
  <p>My guess is that this has something to do with a limitation in the android OS but I hope not. Does anyone know if I'm doing something wrong or can confirm that sockets have these limitations in Android?</p>