• Minabased TCP server examples


    A very simple server-side example here.

    one acceptor plus one handler.

    public class MinaTimeServer
    {
    private static final int PORT = 9123;

    public static void main( String[] args ) throws IOException
    {
    IoAcceptor acceptor = new NioSocketAcceptor();

    /*
    acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
    acceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" ))));
    */

    acceptor.setHandler( new TimeServerHandler() );
    /*
    acceptor.getSessionConfig().setReadBufferSize( 2048 );
    acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
    */
    acceptor.bind( new InetSocketAddress(PORT) );
    }
    }
    public class TimeServerHandler extends IoHandlerAdapter
    {
    /*
    @Override
    public void exceptionCaught( IoSession session, Throwable cause ) throws Exception
    {
    cause.printStackTrace();
    }
    */

    @Override
    public void messageReceived( IoSession session, Object message ) throws Exception
    {
    String str = message.toString();
    if( str.trim().equalsIgnoreCase("quit") ) {
    session.close();
    return;
    }

    Date date = new Date();
    session.write( date.toString() );
    System.out.println("Message written...");
    }

    /*
    @Override
    public void sessionIdle( IoSession session, IdleStatus status ) throws Exception
    {
    System.out.println( "IDLE " + session.getIdleCount( status ));
    }
    */
    }



  • 相关阅读:
    _I、_O、_IO的含义
    ARM启动代码中_main 与用户主程序main()的区别
    ARM汇编程序中的伪指令
    oracle密码过期问题
    等待界面-调转页面前button篇
    等待效果
    winfrom中Application.Restart()
    自动刷新处理
    泛微E8二次开发
    我的菜园子
  • 原文地址:https://www.cnblogs.com/alipayhutu/p/2316508.html
Copyright © 2020-2023  润新知