I'm not using any selectors or anything like that. I just have a simple ServerSocketChannel
listening and a SocketChannel
connecting to it in blocking mode. I want to impose a timeout on the connection, but SocketChannel.socket().setSoTimeout()
does not work.
I tried making a background thread sleep for 30 seconds and checking if a variable is still null
(since it will block waiting to read into that variable) but I couldn't synchronize the variable properly in that I could not access the local variable in my anonymous class.
Are there other ways to accomplish this?
Update: I've worded my question wrong. I also want to have a timeout on read operations as well as the connection itself.