Package org.apache.commons.net
Class DefaultSocketFactory
java.lang.Object
javax.net.SocketFactory
org.apache.commons.net.DefaultSocketFactory
DefaultSocketFactory implements the SocketFactory interface by simply wrapping the java.net.Socket and java.net.ServerSocket constructors. It is the default
SocketFactory used by
SocketClient implementations.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance.DefaultSocketFactory(Proxy proxy) A constructor for sockets with proxy support. -
Method Summary
Modifier and TypeMethodDescriptioncreateServerSocket(int port) Creates a ServerSocket bound to a specified port.createServerSocket(int port, int backlog) Creates a ServerSocket bound to a specified port with a given maximum queue length for incoming connections.createServerSocket(int port, int backlog, InetAddress bindAddr) Creates a ServerSocket bound to a specified port on a given local address with a given maximum queue length for incoming connections.Creates an unconnected Socket.createSocket(String host, int port) Creates a Socket connected to the given host and port.createSocket(String host, int port, InetAddress localAddr, int localPort) Creates a Socket connected to the given host and port and originating from the specified local address and port.createSocket(InetAddress address, int port) Creates a Socket connected to the given host and port.createSocket(InetAddress address, int port, InetAddress localAddr, int localPort) Creates a Socket connected to the given host and port and originating from the specified local address and port.Methods inherited from class javax.net.SocketFactory
getDefault
-
Constructor Details
-
DefaultSocketFactory
public DefaultSocketFactory()Constructs a new instance. -
DefaultSocketFactory
A constructor for sockets with proxy support.- Parameters:
proxy- The Proxy to use when creating new Sockets.- Since:
- 3.2
-
-
Method Details
-
createServerSocket
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:
IOException- If an I/O error occurs while creating the ServerSocket.
-
createServerSocket
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:
IOException- If an I/O error occurs while creating the ServerSocket.
-
createServerSocket
public ServerSocket createServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException 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:
IOException- If an I/O error occurs while creating the ServerSocket.
-
createSocket
Creates an unconnected Socket.- Overrides:
createSocketin classSocketFactory- Returns:
- A new unconnected Socket.
- Throws:
IOException- If an I/O error occurs while creating the Socket.- Since:
- 3.2
-
createSocket
Creates a Socket connected to the given host and port.- Specified by:
createSocketin classSocketFactory- 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:
IOException- If an I/O error occurs while creating the Socket.
-
createSocket
public Socket createSocket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException Creates a Socket connected to the given host and port and originating from the specified local address and port.- Specified by:
createSocketin classSocketFactory- 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:
IOException- If an I/O error occurs while creating the Socket.
-
createSocket
Creates a Socket connected to the given host and port.- Specified by:
createSocketin classSocketFactory- Parameters:
host- The hostname to connect to.port- The port to connect to.- Returns:
- A Socket connected to the given host and port.
- Throws:
UnknownHostException- If the hostname cannot be resolved.IOException- If an I/O error occurs while creating the Socket.
-
createSocket
public Socket createSocket(String host, int port, InetAddress localAddr, int localPort) throws UnknownHostException, IOException Creates a Socket connected to the given host and port and originating from the specified local address and port.- Specified by:
createSocketin classSocketFactory- 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:
UnknownHostException- If the hostname cannot be resolved.IOException- If an I/O error occurs while creating the Socket.
-