package com.server; import java.net.InetSocketAddress; import java.nio.charset.Charset; import org.apache.mina.core.service.IoAcceptor; import org.apache.mina.filter.codec.ProtocolCodecFilter; import org.apache.mina.filter.executor.ExecutorFilter; import org.apache.mina.transport.socket.nio.NioSocketAcceptor; import com.decode.DataObjectDecoder; import com.encode.DataObjectEncode; public class MinaServer { public final static int PORT = 9100; public final static void init() { Charset charset = Charset.forName("utf-8"); IoAcceptor acceptor = new NioSocketAcceptor(); try { acceptor.getFilterChain().addLast("codec",new ProtocolCodecFilter(new DataObjectEncode(charset),new DataObjectDecoder(charset))); acceptor.getFilterChain().addLast("exceutor", new ExecutorFilter()); acceptor.setHandler(new MinaServerHandler()); acceptor.bind( new InetSocketAddress(PORT)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args) { MinaServer.init(); } }
时间: 2024-10-25 15:02:06