1 20 package org.apache.mina.example.proxy; 21 22 import java.net.InetSocketAddress ; 23 24 import org.apache.mina.common.IoAcceptor; 25 import org.apache.mina.common.IoConnector; 26 import org.apache.mina.common.IoConnectorConfig; 27 import org.apache.mina.transport.socket.nio.SocketAcceptor; 28 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; 29 import org.apache.mina.transport.socket.nio.SocketConnector; 30 31 46 public class Main { 47 48 public static void main(String [] args) throws Exception { 49 if (args.length != 3) { 50 System.out.println(Main.class.getName() 51 + " <proxy-port> <server-hostname> <server-port>"); 52 return; 53 } 54 55 IoAcceptor acceptor = new SocketAcceptor(); 57 ((SocketAcceptorConfig) acceptor.getDefaultConfig()) 58 .setReuseAddress(true); 59 60 IoConnector connector = new SocketConnector(); 62 63 ((IoConnectorConfig) connector.getDefaultConfig()) 65 .setConnectTimeout(30); 66 67 ClientToProxyIoHandler handler = new ClientToProxyIoHandler( 68 new ServerToProxyIoHandler(), connector, new InetSocketAddress ( 69 args[1], Integer.parseInt(args[2]))); 70 71 acceptor 73 .bind(new InetSocketAddress (Integer.parseInt(args[0])), handler); 74 75 System.out.println("Listening on port " + Integer.parseInt(args[0])); 76 } 77 78 } 79 | Popular Tags |