Creates a new Connection

@param string      $host
@param integer     $port
@param string|null $password

@return Connection
325437
public function createConnection($host, $port, $password = null)
    {
        $socket = $this->socketFactory->createClient(sprintf('%s:%s', $host, $port));

        $conn = new Connection($socket);

        if (!empty($password)) {
            $conn->authenticate($password);
        }

        return $conn;
    }
623031
public static function factory($host, $port, $sendTimeout = null, $receiveTimeout = null, $framedTransport = false)
    {
        $socket = self::createSocket($host, $port, $sendTimeout, $receiveTimeout);
        $transport = self::createTransport($socket, $framedTransport);
        $protocol = new TBinaryProtocolAccelerated($transport);
        $client = new RestClient($protocol);
        $transport->open();

        return $client;
    }
481653
public function connect($host, $port, $timeout = 1)
    {
        $this->socket = @stream_socket_client(
            "tcp://$host:$port",
            $errorNumber,
            $errorMessage,
            $timeout,
            STREAM_CLIENT_CONNECT,
            stream_context_create($this->options)
        );

        return (bool) $this->socket;
    }
1214465
protected function connect(string $host, int $port): void
    {
        $this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

        if (!$this->socket || !@socket_connect($this->socket, $host, $port)) {
            $error = $this->getLastError();
            throw new CommunicationException($error['message'], $error['code']);
        }
    }
830879
public function connectTcp($host, $port)
    {
        $this->type = 'tcp';
        $pton = @inet_pton($host);
        $fd = null;
        if ($pton === false) { // dirty check
            \PHPDaemon\Clients\DNS\Pool::getInstance()->resolve($this->host, function ($result) use ($host, $port) {
                if (!$result) {
                    Daemon::log(get_class($this) . '->connectTcp : unable to resolve hostname: ' . $host);
                    $this->onStateEv($this->bev, \EventBufferEvent::ERROR);
                    return;
                }
                // @todo stack of addrs
                if (is_array($result)) {
                    if (!sizeof($result)) {
                        return;
                    }
                    srand(Daemon::$process->getPid());
                    $real = $result[rand(0, sizeof($result) - 1)];
                    srand();
                } else {
                    $real = $result;
                }
                $this->connectTcp($real, $port);
            });
            return true;
        }
        $this->hostReal = $host;
        if ($this->host === null) {
            $this->host = $this->hostReal;
        }
        // TCP
        $l = mb_orig_strlen($pton);
        if ($l === 4) {
            $this->addr = $host . ':' . $port;
            if (!$this->bevConnectEnabled) {
                $fd = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
            }
        } elseif ($l === 16) {
            $this->addr = '[' . $host . ']:' . $port;
            if (!$this->bevConnectEnabled) {
                $fd = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
            }
        } else {
            return false;
        }
        if (!$this->bevConnectEnabled && !$fd) {
            return false;
        }
        if (!$this->bevConnectEnabled) {
            socket_set_nonblock($fd);
        }
        if (!$this->bevConnectEnabled) {
            $this->fd = $fd;
            $this->setTimeouts(
                $this->timeoutRead !== null ? $this->timeoutRead : $this->timeout,
                $this->timeoutWrite !== null ? $this->timeoutWrite : $this->timeout
            );
            socket_connect($fd, $host, $port);
            socket_getsockname($fd, $this->locAddr, $this->locPort);
        } else {
            $this->bevConnect = true;
        }
        $this->setFd($fd);
        if (!$this->bev) {
            return false;
        }
        return true;
    }
1103669
protected function sendData($host, $port, $message)
    {
        $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

        return socket_sendto($socket, $message, strlen($message), 0, $host, $port);
    }
717934
public function connect( $host, $port = 21, $timeout = 10 )
	{
		$resource	= @ftp_connect( $host, $port, $timeout );
		if( !$resource )
			return FALSE;
		$this->host	= $host;
		$this->port	= $port;
		$this->resource	= $resource;
		return TRUE;
	}
1200905
public void connect(String hostName, int port) throws UnknownHostException, IOException {
        if (!sslHelper.isSocketAvailable()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                Tr.event(tc, "creating/recreating socket connection to " + hostName + ":" + port);

            SSLSocket socket = sslHelper.createSocket(hostName, port);
            in = new BufferedInputStream(socket.getInputStream());
            out = new BufferedOutputStream(socket.getOutputStream());

            // seqNumber must only be reset to 1 when connection is initialized (as in this case)
            seqNumber = 1;

            // new connection - reset lastUsedTime
            lastUsedTime = System.currentTimeMillis();
        }
    }
1184530
public function listen($port, $host = '0.0.0.0')
    {
        $this->port = $port;
        $this->host = $host;
        
        return $this;
    }
435521
public function connect($host, $username, $password, $dbName, $replicaSet = '', $engine = '', $pConnect = false)
    {
        $authString = "";
        if ($username && $password) {
            $authString = "{$username}:{$password}@";
        }

        $replicaSet && $replicaSet = '?replicaSet=' . $replicaSet;
        $dsn = "mongodb://{$authString}{$host}/{$dbName}{$replicaSet}";

        return new Manager($dsn);
    }
472511
public function createClient($host, $port)
    {
        return $this->connector->create($host, $port)->then(function (DuplexStreamInterface $stream) {
            return new Client($stream);
        });
    }
881170
public function setSqlInfo($host, $user, $password, $database)
    {
        return $this->setSql(new mysqli($host, $user, $password, $database));
    }
232243
private static function createStream(string $host, int $port)
    {
        $uri    = \sprintf('udp://%s:%d', $host, $port);
        $stream = @\stream_socket_client($uri, $errno, $errstr, 0, \STREAM_CLIENT_CONNECT);

        if (false === $stream)
        {
            throw new \RuntimeException(\sprintf('Could not connect to %s', $uri));
        }

        return $stream;
    }
448453
public function create($host, $port, $user, $password, $dbname)
    {
        $params = [
            ':host' => $host,
            ':port' => $port,
            ':user' => $user,
            ':password' => $password,
            ':dbname' => $dbname
        ];

        $query = 'SELECT sbas_id FROM sbas
                  WHERE host = :host AND port = :port AND `user` = :user AND pwd = :password AND dbname = :dbname';
        $statement = $this->connection->executeQuery($query, $params);

        if ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
            return $this->find((int) $row['sbas_id']);
        }

        $query = 'INSERT INTO sbas (ord, host, port, dbname, sqlengine, user, pwd)
              SELECT COALESCE(MAX(ord), 0) + 1 AS ord, :host AS host, :port AS port, :dbname AS dbname,
                     "MYSQL" AS sqlengine, :user AS user, :password AS pwd FROM sbas';

        $stmt = $this->connection->prepare($query);
        $stmt->execute($params);

        $stmt->closeCursor();

        return $this->find((int) $this->connection->lastInsertId());

    }
317037
public static function connect(string $host, int $port = 119, array $options = []): Generator
    {
        // Connect to the remote host.
        $socket = yield from Dns\connect($host, $port, $options);

        // Encoder for encoding and decoding the protocol.
        $encoder = new Rfc3977Encoder();

        // Create the client object.
        $client = new static($socket, $encoder);

        // The server should respond with a welcome message.
        $response = yield from $encoder->readResponse($socket);

        // A 201 response code means posting is not allowed.
        if ($response->code() === 201) {
            $client->postingAllowed = false;
        }

        // Get the server capabilities.
        yield from $client->getServerCapabilities();

        // Set reader client mode if necessary.
        if ($client->hasCapability('MODE-READER') || !$client->hasCapability('READER')) {
            yield from $client->sendCommand(new Command('MODE READER'));
        }

        // Enable encryption if supported.
        if ($client->hasCapability('STARTTLS')) {
            yield from $client->sendCommand(new Command('STARTTLS'));
            yield from $socket->enableCrypto(STREAM_CRYPTO_METHOD_ANY_CLIENT);
        }

        return $client;
    }
189212
function joinServerLan($host, $password = '', $multicall = false)
    {
        if (!is_string($host)) {
            throw new InvalidArgumentException('host = ' . print_r($host, true));
        }
        if (!is_string($password)) {
            throw new InvalidArgumentException('password = ' . print_r($password, true));
        }

        return $this->execute(ucfirst(__FUNCTION__), array(array('Server' => $host, 'ServerPassword' => $password)), $multicall);
    }
1291868
public function connect($host, $port = 80, $secure = false)
    {
        // If the URI should be accessed via SSL, prepend the Hostname with ssl://
        $host = ($secure ? $this->config['ssltransport'] : 'tcp') . '://' . $host;

        // If we are connected to the wrong host, disconnect first
        if (($this->connected_to[0] != $host || $this->connected_to[1] != $port)) {
            if (is_resource($this->socket)) { $this->close();
            }
        }

        // Now, if we are not connected, connect
        if (! is_resource($this->socket) || ! $this->config['keepalive']) {
            $context = stream_context_create();
            if ($secure) {
                if ($this->config['sslcert'] !== null) {
                    if (! stream_context_set_option(
                        $context, 'ssl', 'local_cert',
                        $this->config['sslcert']
                    )
                    ) {
                        include_once 'Zend/Http/Client/Adapter/Exception.php';
                        throw new Zend_Http_Client_Adapter_Exception('Unable to set sslcert option');
                    }
                }
                if ($this->config['sslpassphrase'] !== null) {
                    if (! stream_context_set_option(
                        $context, 'ssl', 'passphrase',
                        $this->config['sslpassphrase']
                    )
                    ) {
                        include_once 'Zend/Http/Client/Adapter/Exception.php';
                        throw new Zend_Http_Client_Adapter_Exception('Unable to set sslpassphrase option');
                    }
                }
            }

            $flags = STREAM_CLIENT_CONNECT;
            if ($this->config['persistent']) { $flags |= STREAM_CLIENT_PERSISTENT;
            }
            
            $this->socket = @stream_socket_client(
                $host . ':' . $port,
                $errno,
                $errstr,
                (int) $this->config['timeout'],
                $flags,
                $context
            );
            if (! $this->socket) {
                $this->close();
                include_once 'Zend/Http/Client/Adapter/Exception.php';
                throw new Zend_Http_Client_Adapter_Exception(
                    'Unable to Connect to ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr
                );
            }

            // Set the stream timeout
            if (! stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
                include_once 'Zend/Http/Client/Adapter/Exception.php';
                throw new Zend_Http_Client_Adapter_Exception('Unable to set the connection timeout');
            }

            // Update connected_to
            $this->connected_to = array($host, $port);
        }
    }