title: EMFILE (Too many open files) error while connecting to LocalServerSocket?
body: <p>My app is pretty simple. Client will connect to a LocalServerSocket (Unix Domain Socket) and send some data and disconnect. If this process repeat over 1024 times, Server throws <code>java.io.IOException: socket failed: EMFILE (Too many open files)</code> when accepting new client.</p>
  
  <p>I have uploaded my demo code here
  <a href="http://speedy.sh/NBSjr/SocketIssue.zip" rel="nofollow">http://speedy.sh/NBSjr/SocketIssue.zip</a></p>
  
  <p>You can see in the code that client closes the connection made before making another connection to the server. In the logcat you can see  FileDescriptor count is increasing in the server and crashes when client connects on 1023rd time.</p>
  
  <p>How do I fix this problem ? Please advice</p>
  
  <p>I tried it on Samsung S4 running Android 4.3. It seems it is reusing file descriptors and my demo app can run for hours!</p>
  
  <p><strong>Updated on 2014-05-19</strong></p>
  
  <p>If you do not have a device running Android 4.4.2 You can try this code on an Emulator running Android 4.4.2</p>