Package com.guxuede.mina.mainserver

Source Code of com.guxuede.mina.mainserver.MinaServer

package com.guxuede.mina.mainserver;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import com.guxuede.mina.codefactory.HttpCodecFactory;

public class MinaServer {
  public static final Charset charset=Charset.forName("UTF-8");
  public static final int port=9000;
 

  /**
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    IoAcceptor acceptor=new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("logger", new LoggingFilter());
    acceptor.getFilterChain().addLast("httpfilter", new ProtocolCodecFilter(new HttpCodecFactory(charset)));
   
    acceptor.setHandler(new ServerHandler());
    //acceptor.getSessionConfig().setMaxReadBufferSize(1024);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 5);
    acceptor.bind(new InetSocketAddress(port));
    //acceptor.dispose();
  }
}
TOP

Related Classes of com.guxuede.mina.mainserver.MinaServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.