import socket


def create_socket_and_connect(address, ssl_context=None):
    """Connect to the Proxy Adapter listening on the provided address, and
    return the socket object.
    If an SSLContext is specified, the connection is established by using the
    wrapped socket.
    """
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    if ssl_context is not None:
        hostname = address[0]
        client_socket = ssl_context.wrap_socket(sock, server_hostname=hostname)
    else:
        client_socket = sock
    client_socket.connect(address)
    return client_socket