Added in API level 1

SocketFactory

abstract class SocketFactory
kotlin.Any
   ↳ javax.net.SocketFactory

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:

  • Due to polymorphism of both factories and sockets, different kinds of sockets can be used by the same application code just by passing it different kinds of factories.
  • Factories can themselves be customized with parameters used in socket construction. So for example, factories could be customized to return sockets with different networking timeouts or security parameters already configured.
  • The sockets returned to the application can be subclasses of java.net.Socket, so that they can directly expose new APIs for features such as compression, security, record marking, statistics collection, or firewall tunneling.

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

Summary

Protected constructors

Creates a SocketFactory.

Public methods
open Socket!

Creates an unconnected socket.

abstract Socket!
createSocket(host: String!, port: Int)

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

abstract Socket!
createSocket(host: String!, port: Int, localHost: InetAddress!, localPort: Int)

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

abstract Socket!
createSocket(host: InetAddress!, port: Int)

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

abstract Socket!
createSocket(address: InetAddress!, port: Int, localAddress: InetAddress!, localPort: Int)

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

open static SocketFactory!

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

Protected constructors

SocketFactory

Added in API level 1
protected SocketFactory()

Creates a SocketFactory.

Public methods

createSocket

Added in API level 1
open fun createSocket(): Socket!

Creates an unconnected socket.

Return
Socket! the unconnected socket
Exceptions
java.io.IOException if the socket cannot be created

createSocket

Added in API level 1
abstract fun createSocket(
    host: String!,
    port: Int
): Socket!

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.

If there is a security manager, its checkConnect method is called with the host address and port as its arguments. This could result in a SecurityException.

Parameters
host String!: the server host name with which to connect, or null for the loopback address.
port Int: the server port
Return
Socket! the Socket
Exceptions
java.io.IOException if an I/O error occurs when creating the socket
java.lang.SecurityException if a security manager exists and its checkConnect method doesn't allow the operation.
java.net.UnknownHostException if the host is not known
java.lang.IllegalArgumentException if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.

createSocket

Added in API level 1
abstract fun createSocket(
    host: String!,
    port: Int,
    localHost: InetAddress!,
    localPort: Int
): Socket!

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.

If there is a security manager, its checkConnect method is called with the host address and port as its arguments. This could result in a SecurityException.

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
Return
Socket! the Socket
Exceptions
java.io.IOException if an I/O error occurs when creating the socket
java.lang.SecurityException if a security manager exists and its checkConnect method doesn't allow the operation.
java.net.UnknownHostException if the host is not known
java.lang.IllegalArgumentException if the port parameter or localPort parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.

createSocket

Added in API level 1
abstract fun createSocket(
    host: InetAddress!,
    port: Int
): Socket!

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.

If there is a security manager, its checkConnect method is called with the host address and port as its arguments. This could result in a SecurityException.

Parameters
host InetAddress!: the server host
port Int: the server port
Return
Socket! the Socket
Exceptions
java.io.IOException if an I/O error occurs when creating the socket
java.lang.SecurityException if a security manager exists and its checkConnect method doesn't allow the operation.
java.lang.IllegalArgumentException if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
java.lang.NullPointerException if host is null.

createSocket

Added in API level 1
abstract fun createSocket(
    address: InetAddress!,
    port: Int,
    localAddress: InetAddress!,
    localPort: Int
): Socket!

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 suplied. The socket is configured using the socket options established for this factory.

If there is a security manager, its checkConnect method is called with the host address and port as its arguments. This could result in a SecurityException.

Parameters
address InetAddress!: the server network address
port Int: the server port
localAddress InetAddress!: the client network address
localPort Int: the client port
Return
Socket! the Socket
Exceptions
java.io.IOException if an I/O error occurs when creating the socket
java.lang.SecurityException if a security manager exists and its checkConnect method doesn't allow the operation.
java.lang.IllegalArgumentException if the port parameter or localPort parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
java.lang.NullPointerException if address is null.

getDefault

Added in API level 1
open static fun getDefault(): SocketFactory!

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

Return
SocketFactory! the default SocketFactory