Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Write timeout on socket  RSS feed

Anton Hinds
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was using plain old sockets to write data but came across the problem that if the other end stops reading for some reason, I just sit there forever. I researched this on the internet and found a lot of responses like "use nio and selectors", but I don't see how this works to implement timeouts.

The SocketChannel class has a write() method on it. This method blocks until all bytes are written or the write is interrupted. If I register a selector, the WRITE_OP only fires when the write buffer is empty or IO gets interrupted for some reason. So if thread A is blocking on a write() and thread B is blocking on a select(), how does this help me trigger a timeout?

Any help is greatly appreciated!

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!