/**
* Only register for interest in R OR W, not both, causes stream
* deadlock after some period of time
*/
if (stream.needsFlush())
key.interestOps(SelectionKey.OP_WRITE);
else
key.interestOps(SelectionKey.OP_READ);
} catch (IOException e) {
// if we have an exception, disconnect the switch