This question regards Java's NIO on Android (2.2, though I can build for higher APIs if necessary): After performing a SocketChannel connect() to a destination IP address, I register my channel for a READ operation. The problem is that when I try to perform a READ on the resulting selected key set, I receive NotYetConnectedException. While I can check the channel's status with isConnectionPending before I try to READ, I would ideally like to have READ keys be selected only when the connection is actually working. Any ideas?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You're doing it wrong.
While the connection is pending, the channel must only be registered for OP_CONNECT.
When OP_CONNECT fires, you must call finishConnect(), and then proceed as follows:
If it returns true, you must then deregister OP_CONNECT, and you may then register OP_READ or OP_WRITE.
If it returns false, do nothing: the connection is still pending.
If it throws an exception, the connect has failed and you must close the channel.