Android: What is a “Bad file number” SocketException?

帅比萌擦擦* 提交于 2020-01-14 10:23:07

问题


I'm getting a "SocketException: Bad file number" while attempting to read from a socket in an Android app and I have no idea what this means. I've googled it and haven't found any explanation of what it is. Any ideas? Thanks.


回答1:


This is usually the result of the underlying socket being closed. The "number" is because file handles in the underlying C code use file numbers to identify handles. The socket may be closed by you, but it may also be closed by security exceptions, flaky network, etc.




回答2:


Do you have something like this in your code ?

       httpClient.getConnectionManager().shutdown();

In my case, I had to shutdown my connectionManager AFTER getting the response



来源:https://stackoverflow.com/questions/5609688/android-what-is-a-bad-file-number-socketexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!