1 20 package org.apache.mina.example.reverser; 21 22 import java.net.InetSocketAddress ; 23 import java.nio.charset.Charset ; 24 25 import org.apache.mina.common.IoAcceptor; 26 import org.apache.mina.filter.LoggingFilter; 27 import org.apache.mina.filter.codec.ProtocolCodecFilter; 28 import org.apache.mina.filter.codec.textline.TextLineCodecFactory; 29 import org.apache.mina.transport.socket.nio.SocketAcceptor; 30 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; 31 32 39 public class Main { 40 private static final int PORT = 8080; 41 42 public static void main(String [] args) throws Exception { 43 IoAcceptor acceptor = new SocketAcceptor(); 44 45 SocketAcceptorConfig cfg = new SocketAcceptorConfig(); 47 cfg.setReuseAddress(true); 48 cfg.getFilterChain().addLast("logger", new LoggingFilter()); 49 cfg.getFilterChain().addLast( 50 "codec", 51 new ProtocolCodecFilter(new TextLineCodecFactory(Charset 52 .forName("UTF-8")))); 53 54 acceptor.bind(new InetSocketAddress (PORT), 56 new ReverseProtocolHandler(), cfg); 57 58 System.out.println("Listening on port " + PORT); 59 } 60 } 61 | Popular Tags |