我的理解是netty支持阻塞(org.jboss.netty.channel.socket.oio)和非阻塞(org.jboss.netty.channel.socket.nio)操作。参见http://docs.jboss.org/netty/3.2/guide/html/architecture.html 2.2 节。
在阻塞和非阻塞之间切换很容易,因此您可以尝试使用 NIO,如果您的客户端不行,您可以切换到 OIO。您将您希望支持的 IO 类型设置为 ChannelFactory
// NIO - non blocking
ChannelFactory factory =
new NioSeverSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
//OIO - blocking
ChannelFactory factory =
new OioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
Run Code Online (Sandbox Code Playgroud)
已经实现了许多现有的基于 netty 的 HTTP Web 服务器/框架。例如,webbit、xitrum和play 框架。我确定还有更多。这些只是我能想到的。
如果您想实现自己的,一个好的起点是org.jboss.netty.example.http包中的示例。