12332

<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));  
    }  




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值