Selector layer

This layer mimics some of the functionality of the selector layer in java, but not provide all the functionality. Currently the MS socket layer does not have this kind of a layer where a set of sockets can be easily monitored for availability of data or to write data etc. If U check this, it is just a wrapper for the "Select" function.

ServerSocket: A wrapper for a socket that can only bind, listen and accept connections.

ClientSocket: A wrapper for accepted connections on the ServerSocket. The ClientSocket will be a selectable channel which can be registered into a Selector for monitoring for data.

SocketSelectionKey: A selection key defines the channel and operation on the channel that needs to be monitored.

SocketSelector: This will act as a selector for operations on the ClientSockets. This can be configured to monitor a maximum number of socket keys. But this will only be considered as a warning and will continue to monitor more socket keys if registered with it.

So a typical usage of this layer will be as below:

ServerSocket svr = new ServerSocket();
Svr.Bind(11000)
ClientSocket sock = svr.Accept(1000)
Selector sel = new SocketSelector();
Sock.register(sel, SockConsts.READ);
Int cnt = Sel.select();
If (cnt > 0)
selectedKeys = sel.selectedKeys();
foreach (SelectionKey key in selectedKeys)
if (key.readable) //read from channel
else if (key.writable) //write to channel
sel.doneSelect(key);
Sock.close();

Last edited Jan 17, 2011 at 10:52 AM by rsankarx, version 2

Comments

No comments yet.