Search in sources :

Example 11 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project pancm_project by xuwujing.

the class MinaServer method main.

/**
 * The entry point of application.
 *
 * @param args the input arguments
 */
/* 启动此类 提示服务端运行成功后
	 * Windows 命令 输入  telnet 127.0.0.1 3305
	 * 然后输入消息  message
	 * 消息为bye的时候关闭连接
	 * */
public static void main(String[] args) {
    IoAcceptor ia = null;
    try {
        // 创建一个非堵塞的server端Socket
        ia = new NioSocketAcceptor();
        // 创建 协议编码解码过滤器ProtocolCodecFilter
        // ProtocolCodecFilter pf=new ProtocolCodecFilter(new TextLineCodecFactory(Charset
        // .forName("UTF-8"),
        // LineDelimiter.WINDOWS.getValue(),
        // LineDelimiter.WINDOWS.getValue()));
        // 设置端口
        InetSocketAddress pt = new InetSocketAddress(PORT);
        // 设置过滤器(使用Mina提供的文本换行符编解码器)
        ia.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
        // 设置读取数据的缓存区大小
        ia.getSessionConfig().setReadBufferSize(2048);
        // 读写通道10秒内无操作进入空闲状态
        ia.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
        // 绑定逻辑处理器
        ia.setHandler(new MinaServerHandler());
        // 绑定端口
        ia.bind(pt);
        logger.info("服务端启动成功...端口号为:" + PORT);
    } catch (Exception e) {
        logger.error("服务器的异常..." + e);
        e.printStackTrace();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ObjectSerializationCodecFactory(org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory) IoAcceptor(org.apache.mina.core.service.IoAcceptor) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor)

Aggregations

NioSocketAcceptor (org.apache.mina.transport.socket.nio.NioSocketAcceptor)11 InetSocketAddress (java.net.InetSocketAddress)10 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)9 IOException (java.io.IOException)4 TextLineCodecFactory (org.apache.mina.filter.codec.textline.TextLineCodecFactory)3 IoAcceptor (org.apache.mina.core.service.IoAcceptor)2 ExecutorFilter (org.apache.mina.filter.executor.ExecutorFilter)2 LoggingFilter (org.apache.mina.filter.logging.LoggingFilter)2 SslFilter (org.apache.mina.filter.ssl.SslFilter)2 SocketSessionConfig (org.apache.mina.transport.socket.SocketSessionConfig)2 FileInputStream (java.io.FileInputStream)1 Charset (java.nio.charset.Charset)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 MapleServerHandler (net.MapleServerHandler)1 MapleCodecFactory (net.mina.MapleCodecFactory)1 Channel (net.server.channel.Channel)1