/* * 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 a.proxy.test;
public class ClientToProxyIoHandler extends AbstractProxyIoHandler { private final ServerToProxyIoHandler connectorHandler = new ServerToProxyIoHandler();
private final IoConnector connector;
private final SocketAddress[] remoteAddress;
public ClientToProxyIoHandler(IoConnector connector, SocketAddress[] remoteAddress) { this.connector = connector; this.remoteAddress = remoteAddress; connector.setHandler(connectorHandler); } InetSocketAddress isas[]=new InetSocketAddress[]{ new InetSocketAddress("113.31.18.232", 22), new InetSocketAddress("113.31.18.233", 22), new InetSocketAddress("113.31.18.234", 22), new InetSocketAddress("113.31.18.235", 22), new InetSocketAddress("113.31.18.236", 22),
}; int k=0; @Override public void sessionOpened(final IoSession session) throws Exception {
/* * 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 a.proxy.test;
public abstract class AbstractProxyIoHandler extends IoHandlerAdapter { private static final Charset CHARSET = Charset.forName("iso8859-1"); public static final String OTHER_IO_SESSION = AbstractProxyIoHandler.class.getName()+".OtherIoSession";
/* * 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 a.proxy.test;
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; public class Main { public static void main(String[] args2) throws Exception { // Create TCP/IP acceptor. NioSocketAcceptor acceptor = new NioSocketAcceptor(); IoConnector connector = new NioSocketConnector(); connector.setConnectTimeoutMillis(30*1000L); ClientToProxyIoHandler handler = new ClientToProxyIoHandler(connector, new InetSocketAddress[]{ new InetSocketAddress("127.0.0.1", 80)}); acceptor.setHandler(handler); acceptor.bind(new InetSocketAddress(777)); System.out.println("Listening on port " + 777); }
[code="java"]/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional infor...