com.mysql.cj.protocol

## Interface SocketFactory

All Superinterfaces:
  SocketMetadata

    public interface SocketFactory
    extends SocketMetadata

Interface to allow pluggable socket creation in the driver

### Method Summary

All Methods Instance Methods Abstract Methods Default Methods
`default void` `afterHandshake()` Called by the driver after completing the MySQL protocol handshake and reading the results of the authentication.
`default void` `beforeHandshake()` Called by the driver before issuing the MySQL protocol handshake.
`<T extends Closeable> T` `connect(String host, int portNumber, PropertySet props, int loginTimeout)` Creates a new socket or channel using the given properties.
`<T extends Closeable> T` `performTlsHandshake(SocketConnection socketConnection, ServerSession serverSession)` If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.
`default <T extends Closeable> T` `performTlsHandshake(SocketConnection socketConnection, ServerSession serverSession, Log log)` If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.

### Methods inherited from interface com.mysql.cj.protocol.SocketMetadata

`isLocallyConnected, isLocallyConnected`

### Method Detail

#### connect

    <T extends Closeable> T connect(String host,
                                    int portNumber,
                                    PropertySet props,
                                    int loginTimeout)
                             throws IOException

Creates a new socket or channel using the given properties. Properties are parsed by the driver from the URL. All properties other than sensitive ones (user and password) are passed to this method. The driver will instantiate the socket factory with the class name given in the property "socketFactory", where the standard is `com.mysql.cj.protocol.StandardSocketFactory` Implementing classes are responsible for handling synchronization of this method (if needed).

Type Parameters:
  `T` - result type
Parameters:
  `host` - the hostname passed in the URL. It will be a single hostname, as the driver parses multi-hosts (for failover) and calls this method for each host connection attempt.
  `portNumber` - the port number to connect to (if required).
  `props` - properties passed to the driver via the URL and/or properties instance.
  `loginTimeout` - login timeout in milliseconds
Returns:
  a socket connected to the given host
Throws:
  `IOException` - if an I/O error occurs

#### beforeHandshake

    default void beforeHandshake()
                          throws IOException

Called by the driver before issuing the MySQL protocol handshake.

Throws:
  `IOException` - if an I/O error occurs

#### performTlsHandshake

    <T extends Closeable> T performTlsHandshake(SocketConnection socketConnection,
                                                ServerSession serverSession)
                                         throws IOException

If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.

Type Parameters:
  `T` - result type
Parameters:
  `socketConnection` - current SocketConnection
  `serverSession` - current ServerSession
Returns:
  SSL socket
Throws:
  `IOException` - if an I/O error occurs

#### performTlsHandshake

    default <T extends Closeable> T performTlsHandshake(SocketConnection socketConnection,
                                                        ServerSession serverSession,
                                                        Log log)
                                                 throws IOException

If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.

Type Parameters:
  `T` - result type
Parameters:
  `socketConnection` - current SocketConnection
  `serverSession` - current ServerSession
  `log` - logger
Returns:
  SSL socket
Throws:
  `IOException` - if an I/O error occurs

#### afterHandshake

    default void afterHandshake()
                         throws IOException

Called by the driver after completing the MySQL protocol handshake and reading the results of the authentication.

Throws:
  `IOException` - if an I/O error occurs

Copyright © 2016, 2025, Oracle and/or its affiliates.