DirectSocketFactory.java

  1. /**
  2.  *
  3.  * Copyright the original author or authors
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smack.proxy;

  18. import java.io.IOException;
  19. import java.net.InetAddress;
  20. import java.net.InetSocketAddress;
  21. import java.net.Proxy;
  22. import java.net.Socket;
  23. import java.net.UnknownHostException;
  24. import javax.net.SocketFactory;

  25. /**
  26.  * SocketFactory for direct connection
  27.  *
  28.  * @author Atul Aggarwal
  29.  */
  30. class DirectSocketFactory
  31.     extends SocketFactory
  32. {

  33.     public DirectSocketFactory()
  34.     {
  35.     }

  36.     public Socket createSocket(String host, int port)
  37.         throws IOException, UnknownHostException
  38.     {
  39.         Socket newSocket = new Socket(Proxy.NO_PROXY);
  40.         newSocket.connect(new InetSocketAddress(host,port));
  41.         return newSocket;
  42.     }

  43.     public Socket createSocket(String host ,int port, InetAddress localHost,
  44.                                 int localPort)
  45.         throws IOException, UnknownHostException
  46.     {
  47.         return new Socket(host,port,localHost,localPort);
  48.     }

  49.     public Socket createSocket(InetAddress host, int port)
  50.         throws IOException
  51.     {
  52.         Socket newSocket = new Socket(Proxy.NO_PROXY);
  53.         newSocket.connect(new InetSocketAddress(host,port));
  54.         return newSocket;
  55.     }

  56.     public Socket createSocket( InetAddress address, int port,
  57.                                 InetAddress localAddress, int localPort)
  58.         throws IOException
  59.     {
  60.         return new Socket(address,port,localAddress,localPort);
  61.     }

  62. }