The javadoc says "With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time" Because I'm using non blocking sockets and this function was written in 1.1, I'm not sure it will do what I want. I don't want to just 'drop' the connection though. I want to know when it was dropped so I can log it and clean up stuff.
Assuming OP can't just drop the connection "the next time it does something AFTER the ten seconds is up" (easiest way, normally most efficient too),
I'm afraid of some hax0r just making connections and letting them sit for an easy DoS. On a non-hax0r note I want to notify the other plays that their opponent has timed out as soon as possible.
Have you tried?
(you should be able to test that very easily with a second machien on your LAN!)
The overhead for additional open channels *using NIO* is sufficiently small that you shouldnt get significant problems beyond your OS problem of running out of sockets.
Even that probably isn't going to happen until long after your server crashes because of lack of open file handles
And how hard is it for someone just to open the connections and then send junk every 1 second? Have you handled that fully?
(not trying to put you off doing it, just pointing out it's quite a long road to go down once you start worrying about that)
- each time you get a selectable key, set a timestamp in a map saying that you just received something at this time, with that key as the key
- separate thread iterates over that map periodically finding victims, and uses the selectable key objects to remove them from the selector and drop the channel
I'm currently doing something very similar. I have a DelayQueue running in another Thread.