1 /** 2 * $RCSfile$ 3 * $Revision$ 4 * $Date$ 5 * 6 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.jivesoftware.smack.proxy; 19 20 import java.io.IOException; 21 import java.net.InetAddress; 22 import java.net.InetSocketAddress; 23 import java.net.Proxy; 24 import java.net.Socket; 25 import java.net.UnknownHostException; 26 import javax.net.SocketFactory; 27 28 /** 29 * SocketFactory for direct connection 30 * 31 * @author Atul Aggarwal 32 */ 33 class DirectSocketFactory 34 extends SocketFactory 35 { 36 37 public DirectSocketFactory() 38 { 39 } 40 41 static private int roundrobin = 0; 42 43 public Socket createSocket(String host, int port) 44 throws IOException, UnknownHostException 45 { 46 Socket newSocket = new Socket(Proxy.NO_PROXY); 47 InetAddress resolved[] = InetAddress.getAllByName(host); 48 newSocket.connect(new InetSocketAddress(resolved[(roundrobin++) % resolved.length],port)); 49 return newSocket; 50 } 51 52 public Socket createSocket(String host ,int port, InetAddress localHost, 53 int localPort) 54 throws IOException, UnknownHostException 55 { 56 return new Socket(host,port,localHost,localPort); 57 } 58 59 public Socket createSocket(InetAddress host, int port) 60 throws IOException 61 { 62 Socket newSocket = new Socket(Proxy.NO_PROXY); 63 newSocket.connect(new InetSocketAddress(host,port)); 64 return newSocket; 65 } 66 67 public Socket createSocket( InetAddress address, int port, 68 InetAddress localAddress, int localPort) 69 throws IOException 70 { 71 return new Socket(address,port,localAddress,localPort); 72 } 73 74 } 75