任何NIO框架.NET? [英] Any NIO frameworks for .NET?
问题描述
是否有.NET任何非阻塞IO框架?
Are there any non-blocking IO frameworks for .NET?
我要寻找类似于阿帕奇米娜东西,的的JBoss的Netty 为Java:实现高度可扩展的服务器架构 - 不仅仅是底层支持的.NET框架提供
I am looking for something similar to what Apache Mina and JBoss Netty provides for Java: a framework for implementing highly scalable servers - not just the low-level support that the .NET framework provides.
编辑:为了更好地解释什么,我想看看,这里是你可以用米娜做一个基本的例子:
To better explain what I would like to see, here is a basic example of what you can do with Mina:
在米纳我可以实现这样的ProtocolDe codeR:
In Mina I can implement a ProtocolDecoder like this:
public class SimpleDecoder extends CumulativeProtocolDecoder {
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
if (in.remaining() < 4)
return false;
int length = in.getInt();
if(in.remaining() < 4 + length)
return false;
Command command = new Command(in.asInputStream());
out.write(command);
}
}
和这样的CommandHandler:
And a CommandHandler like this:
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.
}
}
如果我通过调用启动服务器
If I start the server by calling
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();
我将得到一个非阻塞服务器
I will get a non-blocking server.
这将运行一个单一的(或至少是短短数)的线程,通过所有传入连接循环,从插座收集数据,并调用 SimpleDe coder.doDe code( )
,看它是否有连接上一个完整的命令。然后,它会通过命令 CommandHandler.messageReceived()
,我可以接管处理。
It will run a single (or at least just a few) threads, cycling through all incoming connections, gathering data from the sockets, and call SimpleDecoder.doDecode()
to see if it has a complete command on the connection. Then it will pass the command to CommandHandler.messageReceived()
, and I can take over the processing.
推荐答案
您可以看看SuperSocket, HTTP://supersocket.$c$cplex.com/ 它可能不是很强的像米娜和Netty的,但它是一种简单的框架,可以方便地使用。
You can take a look at SuperSocket, http://supersocket.codeplex.com/ It may not be strong like Mina and Netty, but it is kind of simple framework you can use easily.
这篇关于任何NIO框架.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!