All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.mina.example.proxy.Main Maven / Gradle / Ivy

The newest version!
/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *
 */
package org.apache.mina.example.proxy;


import java.net.InetSocketAddress;

import org.apache.mina.core.service.IoConnector;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketConnector;


/**
 * (Entry point) Demonstrates how to write a very simple tunneling proxy
 * using MINA. The proxy only logs all data passing through it. This is only
 * suitable for text based protocols since received data will be converted into
 * strings before being logged.
 * 

* Start a proxy like this:
* org.apache.mina.example.proxy.Main 12345 www.google.com 80
* and open http://localhost:12345 in a * browser window. * * @author Apache MINA Project */ public class Main { public static void main( String[] args ) throws Exception { if ( args.length != 3 ) { System.out.println( Main.class.getName() + " " ); return; } // Create TCP/IP acceptor. NioSocketAcceptor acceptor = new NioSocketAcceptor(); // Create TCP/IP connector. IoConnector connector = new NioSocketConnector(); // Set connect timeout. connector.setConnectTimeoutMillis( 30 * 1000L ); ClientToProxyIoHandler handler = new ClientToProxyIoHandler( connector, new InetSocketAddress( args[1], Integer.parseInt( args[2] ) ) ); // Start proxy. acceptor.setHandler( handler ); acceptor.bind( new InetSocketAddress( Integer.parseInt( args[0] ) ) ); System.out.println( "Listening on port " + Integer.parseInt( args[0] ) ); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy