Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.commons.net;
 
 import java.net.Proxy;
 
DefaultSocketFactory implements the SocketFactory interface by simply wrapping the java.net.Socket and java.net.ServerSocket constructors. It is the default SocketFactory used by org.apache.commons.net.SocketClient implementations.

See also:
javax.net.SocketFactory
SocketClient
SocketClient.setSocketFactory
 
 
 public class DefaultSocketFactory extends SocketFactory
 {
    
The proxy to use when creating new sockets.
 
     private final Proxy connProxy;

    
The default constructor.
 
     public DefaultSocketFactory()
     {
         this(null);
     }

    
A constructor for sockets with proxy support.

Parameters:
proxy The Proxy to use when creating new Sockets.
Since:
3.2
 
     public DefaultSocketFactory(Proxy proxy)
     {
          = proxy;
     }

    
Creates an unconnected Socket.

Returns:
A new unconnected Socket.
Throws:
java.io.IOException If an I/O error occurs while creating the Socket.
Since:
3.2
 
     @Override
     public Socket createSocket() throws IOException
     {
         if ( != null)
         {
             return new Socket();
         }
         return new Socket();
     }

    
Creates a Socket connected to the given host and port.

Parameters:
host The hostname to connect to.
port The port to connect to.
Returns:
A Socket connected to the given host and port.
Throws:
java.net.UnknownHostException If the hostname cannot be resolved.
java.io.IOException If an I/O error occurs while creating the Socket.
 
     @Override
     public Socket createSocket(String hostint port)
     {
         if ( != null)
         {
             Socket s = new Socket();
            s.connect(new InetSocketAddress(hostport));
            return s;
        }
        return new Socket(hostport);
    }

    
Creates a Socket connected to the given host and port.

Parameters:
address The address of the host to connect to.
port The port to connect to.
Returns:
A Socket connected to the given host and port.
Throws:
java.io.IOException If an I/O error occurs while creating the Socket.
    @Override
    public Socket createSocket(InetAddress addressint port)
    throws IOException
    {
        if ( != null)
        {
            Socket s = new Socket();
            s.connect(new InetSocketAddress(addressport));
            return s;
        }
        return new Socket(addressport);
    }

    
Creates a Socket connected to the given host and port and originating from the specified local address and port.

Parameters:
host The hostname to connect to.
port The port to connect to.
localAddr The local address to use.
localPort The local port to use.
Returns:
A Socket connected to the given host and port.
Throws:
java.net.UnknownHostException If the hostname cannot be resolved.
java.io.IOException If an I/O error occurs while creating the Socket.
    @Override
    public Socket createSocket(String hostint port,
                               InetAddress localAddrint localPort)
    {
        if ( != null)
        {
            Socket s = new Socket();
            s.bind(new InetSocketAddress(localAddrlocalPort));
            s.connect(new InetSocketAddress(hostport));
            return s;
        }
        return new Socket(hostportlocalAddrlocalPort);
    }

    
Creates a Socket connected to the given host and port and originating from the specified local address and port.

Parameters:
address The address of the host to connect to.
port The port to connect to.
localAddr The local address to use.
localPort The local port to use.
Returns:
A Socket connected to the given host and port.
Throws:
java.io.IOException If an I/O error occurs while creating the Socket.
    @Override
    public Socket createSocket(InetAddress addressint port,
                               InetAddress localAddrint localPort)
    throws IOException
    {
        if ( != null)
        {
            Socket s = new Socket();
            s.bind(new InetSocketAddress(localAddrlocalPort));
            s.connect(new InetSocketAddress(addressport));
            return s;
        }
        return new Socket(addressportlocalAddrlocalPort);
    }

    
Creates a ServerSocket bound to a specified port. A port of 0 will create the ServerSocket on a system-determined free port.

Parameters:
port The port on which to listen, or 0 to use any free port.
Returns:
A ServerSocket that will listen on a specified port.
Throws:
java.io.IOException If an I/O error occurs while creating the ServerSocket.
    public ServerSocket createServerSocket(int portthrows IOException
    {
        return new ServerSocket(port);
    }

    
Creates a ServerSocket bound to a specified port with a given maximum queue length for incoming connections. A port of 0 will create the ServerSocket on a system-determined free port.

Parameters:
port The port on which to listen, or 0 to use any free port.
backlog The maximum length of the queue for incoming connections.
Returns:
A ServerSocket that will listen on a specified port.
Throws:
java.io.IOException If an I/O error occurs while creating the ServerSocket.
    public ServerSocket createServerSocket(int portint backlog)
    throws IOException
    {
        return new ServerSocket(portbacklog);
    }

    
Creates a ServerSocket bound to a specified port on a given local address with a given maximum queue length for incoming connections. A port of 0 will create the ServerSocket on a system-determined free port.

Parameters:
port The port on which to listen, or 0 to use any free port.
backlog The maximum length of the queue for incoming connections.
bindAddr The local address to which the ServerSocket should bind.
Returns:
A ServerSocket that will listen on a specified port.
Throws:
java.io.IOException If an I/O error occurs while creating the ServerSocket.
    public ServerSocket createServerSocket(int portint backlog,
                                           InetAddress bindAddr)
    throws IOException
    {
        return new ServerSocket(portbacklogbindAddr);
    }
New to GrepCode? Check out our FAQ X