n(i)o fun

So anyways, I was just taking a break from normal things screwing around with some old code of mine, and I got an urge to revisit some nio stuff I had just started on before I went and did other things.

My only problem so far is how to neatly idenitfy one socket channel from another when I retrieve it from a key. If I accept incoming connections and register them with a selector for read/write and then later I get a key that wants to read, well, which socket channel is this?

This is all smelling like I’m going to have to just stick them in an array somewhere and loop through and see what needs to read/write manually so I can tell them apart.

This also needs to just work for something non-specific like, a telnet client, so no funny ident bytes in the streams or silly shit like that.

meh?

I think you want to take a look at the register() function in SelectableChannel. The last parameter is an Object attachment that can be retrieved from the SelectionKey with attachment().

  • elias

sonofa… hidden in plain sight. My bad. :wink: If that works how I think, it solves all my problems.

Thanks.