12332
2015-12-18 14:24
309 查看
<ol><li><span style="font-family: Arial, Helvetica, sans-serif;">public class MinaTimeTest { </span></li></ol> private static final int PORT = 9123; public static void main(String[] args) throws IOException { //首先,我们为服务端创建IoAcceptor,NioSocketAcceptor是基于NIO的服务端监听器 IoAcceptor acceptor = new NioSocketAcceptor(); //接着,如结构图示,在Acceptor和IoHandler之间将设置一系列的Fliter //包括记录过滤器和编解码过滤器。其中TextLineCodecFactory是mina自带的文本解编码器 acceptor.getFilterChain().addLast("logger", new LoggingFilter()); acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8")))); //配置事务处理Handler,将请求转由TimeServerHandler处理。 acceptor.setHandler(new TimeServerHandler()); //配置Buffer的缓冲区大小 acceptor.getSessionConfig().setReadBufferSize(2048); //设置等待时间,每隔IdleTime将调用一次handler.sessionIdle()方法 acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10); //绑定端口 acceptor.bind(new InetSocketAddress(PORT)); }
相关文章推荐
- PHP rabbitmq
- DLL工程调试
- bounds和frame
- 接口适配器模式
- Linux 常用命令
- 现代优化算法 之 模拟退火
- [LeetCode] Dp
- 三种弹窗提醒代码范例
- 問題排查:在 ServiceModel 客戶端配置部份中,找不到名稱 和協定 的終結點元素。
- 简单了解文档碎片DocumentFragment的使用
- binary search(java)
- Node.js 究竟是什么?
- 运行MySQL远程连接
- Java原型模式之基础
- leetcode(303)Range Sum Query - Immutable js代码实现
- willMoveToParentViewController和didMoveToParentViewController
- Win10怎么屏蔽指定的网站?
- Windows Server 2008 R2 安裝 Oracle 10g
- 列表视图ListView和ListActivity
- 正则表达式之去除空行