1 20 package org.apache.mina.example.httpserver.codec; 21 22 import java.net.InetSocketAddress ; 23 24 import org.apache.mina.common.IoAcceptor; 25 import org.apache.mina.filter.LoggingFilter; 26 import org.apache.mina.filter.codec.ProtocolCodecFilter; 27 import org.apache.mina.transport.socket.nio.SocketAcceptor; 28 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; 29 30 36 public class Server { 37 38 private static int DEFAULT_PORT = 8080; 39 40 41 public static final String VERSION_STRING = "$Revision: 555855 $ $Date: 2007-07-13 12:19:00 +0900 (금, 13 7월 2007) $"; 42 43 public static void main(String [] args) { 44 int port = DEFAULT_PORT; 45 46 for (int i = 0; i < args.length; i++) { 47 if (args[i].equals("-port")) { 48 port = Integer.parseInt(args[i + 1]); 49 } 50 } 51 52 try { 53 IoAcceptor acceptor = new SocketAcceptor(); 55 56 SocketAcceptorConfig cfg = new SocketAcceptorConfig(); 58 cfg.setReuseAddress(true); 59 cfg.getFilterChain().addLast( 60 "protocolFilter", 61 new ProtocolCodecFilter( 62 new HttpServerProtocolCodecFactory())); 63 cfg.getFilterChain().addLast("logger", new LoggingFilter()); 64 65 acceptor 66 .bind(new InetSocketAddress (port), new ServerHandler(), cfg); 67 68 System.out.println("Server now listening on port " + port); 69 } catch (Exception ex) { 70 ex.printStackTrace(); 71 } 72 } 73 } 74 | Popular Tags |