title: Set socket opt failed bad file number exception
body: <p>Am getting set socket option failed exception in Android. What am I doing wrong ?</p>
  
  <pre><code>    setsockopt failed: EBADF (Bad file number)
  </code></pre>
  
  <p>For the following code:</p>
  
  <pre><code>int timeout = 500;
  
  
  
  Socket socket = new Socket(InetAddress.getByAddress(new byte[]{10, 0, 2, 2}),
                              Integer.parseInt(m.destPort));
                      ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
                      oos.writeObject(m);
                      oos.close();
                      socket.setSoTimeout(timeOut);
                      ObjectInputStream iis = new ObjectInputStream(socket.getInputStream());
                      iis.readObject();
                      iis.close();
                      socket.close();
  </code></pre>