Reputation: 5550
I have an Android app that has a Socket open. I would like to write to this socket without any possibility of blocking the thread on the write for a noticeable amount of time. If any IO error occurs, I would like the write to just silently fail. Is there an easy way to do this?
Upvotes: 1
Views: 3548
Reputation: 121649
You might want to consider looking at NIO:
http://developer.android.com/reference/java/nio/channels/package-summary.html
Upvotes: 2
Reputation: 223023
Yes, NIO provides a SocketChannel
class (call the getChannel
method on your Socket
), which allows you to call configureBlocking
to use non-blocking mode. You should then do all your I/O through the channel, and not through the Socket
object.
Upvotes: 3