Skip to content

Most visited

Recently visited

navigation
Added in API level 1

SocketFactory

public abstract class SocketFactory
extends Object

java.lang.Object
   ↳ javax.net.SocketFactory
Known Direct Subclasses
Known Indirect Subclasses


This abstract class defines methods to create sockets. It can be subclassed to create specific socket types with additional socket-level functionality.

Summary

Protected constructors

SocketFactory()

Creates a new SocketFactory instance.

Public methods

abstract Socket createSocket(String host, int port, InetAddress localHost, int localPort)

Creates a new socket which is connected to the remote host specified by the parameters host and port.

abstract Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)

Creates a new socket which is connected to the remote host specified by the InetAddress address.

abstract Socket createSocket(InetAddress host, int port)

Creates a new socket which is connected to the remote host specified by the InetAddress host.

abstract Socket createSocket(String host, int port)

Creates a new socket which is connected to the remote host specified by the parameters host and port.

Socket createSocket()

Creates a new socket which is not connected to any remote host.

static SocketFactory getDefault()

Gets the default socket factory of the system which can be used to create new sockets without creating a subclass of this factory.

Inherited methods

From class java.lang.Object

Protected constructors

SocketFactory

Added in API level 1
SocketFactory ()

Creates a new SocketFactory instance.

Public methods

createSocket

Added in API level 1
Socket createSocket (String host, 
                int port, 
                InetAddress localHost, 
                int localPort)

Creates a new socket which is connected to the remote host specified by the parameters host and port. The socket is bound to the local network interface specified by the InetAddress localHost on port localPort.

Parameters
host String: the remote host address the socket has to be connected to.
port int: the port number of the remote host at which the socket is connected.
localHost InetAddress: the local host address the socket is bound to.
localPort int: the port number of the local host at which the socket is bound.
Returns
Socket the created connected socket.
Throws
IOException if an error occurs while creating a new socket.
UnknownHostException if the specified host is unknown or the IP address could not be resolved.

createSocket

Added in API level 1
Socket createSocket (InetAddress address, 
                int port, 
                InetAddress localAddress, 
                int localPort)

Creates a new socket which is connected to the remote host specified by the InetAddress address. The socket is bound to the local network interface specified by the InetAddress localHost on port localPort.

Parameters
address InetAddress: the remote host address the socket has to be connected to.
port int: the port number of the remote host at which the socket is connected.
localAddress InetAddress: the local host address the socket is bound to.
localPort int: the port number of the local host at which the socket is bound.
Returns
Socket the created connected socket.
Throws
IOException if an error occurs while creating a new socket.

createSocket

Added in API level 1
Socket createSocket (InetAddress host, 
                int port)

Creates a new socket which is connected to the remote host specified by the InetAddress host. The socket is bound to any available local address and port.

Parameters
host InetAddress: the host address the socket has to be connected to.
port int: the port number of the remote host at which the socket is connected.
Returns
Socket the created connected socket.
Throws
IOException if an error occurs while creating a new socket.

createSocket

Added in API level 1
Socket createSocket (String host, 
                int port)

Creates a new socket which is connected to the remote host specified by the parameters host and port. The socket is bound to any available local address and port.

Parameters
host String: the remote host address the socket has to be connected to.
port int: the port number of the remote host at which the socket is connected.
Returns
Socket the created connected socket.
Throws
IOException if an error occurs while creating a new socket.
UnknownHostException if the specified host is unknown or the IP address could not be resolved.

createSocket

Added in API level 1
Socket createSocket ()

Creates a new socket which is not connected to any remote host. This method has to be overridden by a subclass otherwise a SocketException is thrown.

Returns
Socket the created unconnected socket.
Throws
IOException if an error occurs while creating a new socket.

getDefault

Added in API level 1
SocketFactory getDefault ()

Gets the default socket factory of the system which can be used to create new sockets without creating a subclass of this factory.

Returns
SocketFactory the system default socket factory.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.