APIdia Launch Partner
Top Description Fields Constructors Methods
javax.net

public abstract Class SocketFactory

Additional top-level class in compilation unit: DefaultSocketFactory.

extends Object
Class Inheritance
Known Direct Subclasses
javax.net.DefaultSocketFactory, javax.net.ssl.SSLSocketFactory
Imports
java.io.IOException, java.net.InetAddress, .Socket, .SocketException, .UnknownHostException

This class creates sockets. It may be subclassed by other factories, which create particular subclasses of sockets and thus provide a general framework for the addition of public socket-level functionality.

Socket factories are a simple way to capture a variety of policies related to the sockets being constructed, producing such sockets in a way which does not require special configuration of the code which asks for the sockets:

Factory classes are specified by environment-specific configuration mechanisms. For example, the getDefault method could return a factory that was appropriate for a particular application, and a framework could use a factory customized to its own purposes.

Author
David Brownell
Since
1.4
See Also
ServerSocketFactory

Field Summary

Modifier and TypeField and Description
private static SocketFactory

Constructor Summary

AccessConstructor and Description
protected
SocketFactory()

Creates a SocketFactory.

Method Summary

Modifier and TypeMethod and Description
public Socket

Returns:

the unconnected socket
createSocket
()

Creates an unconnected socket.

public abstract Socket

Returns:

the Socket
createSocket
(String
the server host name with which to connect, or null for the loopback address.
host
,
int
the server port
port
)

Creates a socket and connects it to the specified remote host at the specified remote port.

public abstract Socket

Returns:

the Socket
createSocket
(String
the server host name with which to connect, or null for the loopback address.
host
,
int
the server port
port
,
InetAddress
the local address the socket is bound to
localHost
,
int
the local port the socket is bound to
localPort
)

Creates a socket and connects it to the specified remote host on the specified remote port.

public abstract Socket

Returns:

the Socket
createSocket
(InetAddress
the server host
host
,
int
the server port
port
)

Creates a socket and connects it to the specified port number at the specified address.

public abstract Socket

Returns:

the Socket
createSocket
(InetAddress
the server network address
address
,
int
the server port
port
,
InetAddress
the client network address
localAddress
,
int
the client port
localPort
)

Creates a socket and connect it to the specified remote address on the specified remote port.

public static SocketFactory

Returns:

the default SocketFactory
getDefault
()

Returns a copy of the environment's default socket factory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

theFactoryback to summary
private static SocketFactory theFactory

Constructor Detail

SocketFactoryback to summary
protected SocketFactory()

Creates a SocketFactory.

Method Detail

createSocketback to summary
public Socket createSocket() throws IOException

Creates an unconnected socket.

Returns:Socket

the unconnected socket

Exceptions
IOException:
if the socket cannot be created
See Also
java.net.Socket#connect(java.net.SocketAddress), java.net.Socket#connect(java.net.SocketAddress, int), java.net.Socket#Socket()
createSocketback to summary
public abstract Socket createSocket(String host, int port) throws IOException, UnknownHostException

Creates a socket and connects it to the specified remote host at the specified remote port. This socket is configured using the socket options established for this factory.

Parameters
host:String

the server host name with which to connect, or null for the loopback address.

port:int

the server port

Returns:Socket

the Socket

Exceptions
IOException:
if an I/O error occurs when creating the socket
UnknownHostException:
if the host is not known
IllegalArgumentException:
if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
See Also
java.net.Socket#Socket(String, int)
createSocketback to summary
public abstract Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException

Creates a socket and connects it to the specified remote host on the specified remote port. The socket will also be bound to the local address and port supplied. This socket is configured using the socket options established for this factory.

Parameters
host:String

the server host name with which to connect, or null for the loopback address.

port:int

the server port

localHost:InetAddress

the local address the socket is bound to

localPort:int

the local port the socket is bound to

Returns:Socket

the Socket

Exceptions
IOException:
if an I/O error occurs when creating the socket
UnknownHostException:
if the host is not known
IllegalArgumentException:
if the port parameter or localPort parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
See Also
java.net.Socket#Socket(String, int, java.net.InetAddress, int)
createSocketback to summary
public abstract Socket createSocket(InetAddress host, int port) throws IOException

Creates a socket and connects it to the specified port number at the specified address. This socket is configured using the socket options established for this factory.

Parameters
host:InetAddress

the server host

port:int

the server port

Returns:Socket

the Socket

Exceptions
IOException:
if an I/O error occurs when creating the socket
IllegalArgumentException:
if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
NullPointerException:
if host is null.
See Also
java.net.Socket#Socket(java.net.InetAddress, int)
createSocketback to summary
public abstract Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException

Creates a socket and connect it to the specified remote address on the specified remote port. The socket will also be bound to the local address and port supplied. The socket is configured using the socket options established for this factory.

Parameters
address:InetAddress

the server network address

port:int

the server port

localAddress:InetAddress

the client network address

localPort:int

the client port

Returns:Socket

the Socket

Exceptions
IOException:
if an I/O error occurs when creating the socket
IllegalArgumentException:
if the port parameter or localPort parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
NullPointerException:
if address is null.
See Also
java.net.Socket#Socket(java.net.InetAddress, int, java.net.InetAddress, int)
getDefaultback to summary
public static SocketFactory getDefault()

Returns a copy of the environment's default socket factory.

Returns:SocketFactory

the default SocketFactory