Reputation: 7048
I am trying to understand the NIO Sockets model and I have a few questions that I want to clear up.
Is it possible that you can register more than one Server channels with selector i.e.
serverChannel_1.register(selector, SelectionKey.OP_ACCEPT);
serverChannel_2.register(selector, SelectionKey.OP_ACCEPT);
// and so on ....?
So, by registering two ServerSocketChannel are you having two servers on the same machine on different ports?
What are the "keys" in this following nio socket model:
From what I can tell is that the long client I/O requests are divided into small chunks and handled one after another. i.e. say 10% of request from client 1, 2, 3 is processed at a time and loop starts again?
Upvotes: 1
Views: 325
Reputation: 311028
Yes.
A SelectionKey
Is the result of registering a channel with a selector. It represents the registration, if you like. It has as properties the channel that was registered, the event(s) it was registered for, and the event(s) if any that are currently ready.
From what I can tell is that the long client I/O requests are divided into small chunks and handled one after another. i.e. say 10% of request from client 1, 2, 3 is processed at a time and loop starts again?
No. How you handle client I/O is entirely up to you. All the Selector
does is tell you which events are ready on which channels.
Upvotes: 1