title: Any NIO frameworks for .NET?
body: <p>Are there any non-blocking IO frameworks for .NET? </p>
  
  <p>I am looking for something similar to what <a href="http://mina.apache.org/" rel="noreferrer">Apache Mina</a> and <a href="http://www.jboss.org/netty" rel="noreferrer">JBoss Netty</a> provides for Java: a framework for implementing highly scalable servers - not just the low-level support that the .NET framework provides.</p>
  
  <p><strong>EDIT:</strong> To better explain what I would like to see, here is a basic example of what you can do with Mina:</p>
  
  <p>In Mina I can implement a ProtocolDecoder like this:</p>
  
  <pre><code>public class SimpleDecoder extends CumulativeProtocolDecoder {
    protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
      if (in.remaining() &lt; 4) 
        return false;
      int length = in.getInt();
      if(in.remaining() &lt; 4 + length)
        return false;
      Command command = new Command(in.asInputStream());
      out.write(command);
    }
  }
  </code></pre>
  
  <p>And a CommandHandler like this:</p>
  
  <pre><code>public abstract class CommandHandler extends IoHandlerAdapter{
    public void messageReceived(IoSession session, Object message) throws IOException, CloneNotSupportedException {
      Command command = (Command) message;
      // Handle command. Probably by putting it in a workqueue.
    }
  }
  </code></pre>
  
  <p>If I start the server by calling</p>
  
  <pre><code>CommandHandler handler = new CommandHandler();
  NioSocketAcceptor acceptor = new NioSocketAcceptor();
  acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new SimpleDecoder(false)));
  acceptor.setLocalAddress(new InetSocketAddress(port));
  acceptor.setHandler(handler);
  acceptor.bind();
  </code></pre>
  
  <p>I will get a non-blocking server.</p>
  
  <p>It will run a single (or at least just a few) threads, cycling through all incoming connections, gathering data from the sockets, and call <code>SimpleDecoder.doDecode()</code> to see if it has a complete command on the connection. Then it will pass the command to <code>CommandHandler.messageReceived()</code>, and I can take over the processing.</p>