Connect to the server
9136
def connect
    site = @proxy || @dest
    begin
      retry_number = 0
      timeout(@connect_timeout) do
        @socket = create_socket(site)
        begin
          @src.host = @socket.addr[3]
          @src.port = @socket.addr[1]
        rescue SocketError
          # to avoid IPSocket#addr problem on Mac OS X 10.3 + ruby-1.8.1.
          # cf. [ruby-talk:84909], [ruby-talk:95827]
        end
        if @dest.scheme == 'https'
          @socket = create_ssl_socket(@socket)
          connect_ssl_proxy(@socket) if @proxy
          @socket.ssl_connect
          @socket.post_connection_check(@dest)
          @ssl_peer_cert = @socket.peer_cert
        end
        # Use Ruby internal buffering instead of passing data immediatly
        # to the underlying layer
        # => we need to to call explicitely flush on the socket
        @socket.sync = @socket_sync
      end
    rescue TimeoutError
      if @connect_retry == 0
        retry
      else
        retry_number += 1
        retry if retry_number < @connect_retry
      end
      close
      raise
    end

    @state = :WAIT
    @readbuf = ''
  end
714100
def connect(self):
        """"""
        if not getattr(self._local, 'conn', None):
            try:
                server = self._servers.get()
                logger.debug('Connecting to %s', server)
                self._local.conn = ClientTransport(server, self._framed_transport,
                    self._timeout, self._recycle)
            except (Thrift.TException, socket.timeout, socket.error):
                logger.warning('Connection to %s failed.', server)
                self._servers.mark_dead(server)
                return self.connect()
        return self._local.conn
863975
def _connect(self):
        
        self.conn = self._create_connection()
        spawn(self.conn.connect)
        self.set_nick(self.nick)
        self.cmd(u'USER', u'{0} 3 * {1}'.format(self.nick, self.realname))
251163
protected function connect()
    {
        $schema = ($this->_secure === 'ssl' || $this->_secure === 'tls' ? $this->_secure . '://' : '');
        $url = $schema  . $this->_host . ':' . $this->_port;
        $this->_connection = stream_socket_client($url, $errno, $error, $this->_timeout, STREAM_CLIENT_CONNECT, $this->_context);
        if (!$this->_connection) {
            throw new NetException($error, $errno);
        }
        stream_set_timeout($this->_connection, $this->_timeout, 0);
        $this->read();

        $this->write("EHLO {$this->_client}");
        $ehloResponse = $this->read();

        if ($this->_secure === 'starttls') {
            $this->write('STARTTLS', 220);
            if (!stream_socket_enable_crypto($this->_connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
                throw new NetException('Unable to connect via TLS.');
            }
            $this->write("EHLO {$this->_client}", 250);
        }

        if ($this->_username !== null && $this->_password !== null) {
            $authMechanisms = [];
            if (preg_match('~^250[ -]AUTH (.*)$~im', $ehloResponse, $matches)) {
                $authMechanisms = explode(' ', trim($matches[1]));
            }

            if (in_array('PLAIN', $authMechanisms, true)) {
                $credentials = $this->_username . "\0" . $this->_username . "\0" . $this->_password;
                $this->write('AUTH PLAIN ' . base64_encode($credentials), 235, 'PLAIN credentials');
            } else {
                $this->write('AUTH LOGIN', 334);
                $this->write(base64_encode($this->_username), 334, 'username');
                $this->write(base64_encode($this->_password), 235, 'password');
            }
        }
    }
775818
def __connect(self):
        """"""
        try:
            logger.debug("Socket connecting to %s:%s", self.host, self.port)
            self.sock.connect((self.host, self.port))
        except socket.error as e:
            logger.exception("socket error %s", e)
            logger.error("Closing socket and recreating a new one.")
            self.sock.close()
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.connect((self.host, self.port))
470031
def connect(self):
        """"""
        device = None
        # logger.debug("Connecting to: {}".format(str(self)))
        for device in self.devices:
            if not device.connected:
                self.connection.emit_message("Connecting {}".format(str(device)), log_level=logging.INFO)
                protocol_name = device.get_protocol_name()
                device.protocol = make_protocol(protocol_name, device)
                command = device.protocol.get_command()
                self.ctrl.spawn_session(command=command)
                try:
                    result = device.connect(self.ctrl)
                except CommandSyntaxError as exc:
                    # all commands during discovery provides itself in exception except
                    # spawn session which is handled differently. If command syntax error is detected during spawning
                    # a new session then the problem is either on jumphost or csm server.
                    # The problem with spawning session is detected in connect FSM for telnet and ssh.
                    if exc.command:
                        cmd = exc.command
                        host = device.hostname
                    else:
                        cmd = command
                        host = "Jumphost/CSM"

                    self.connection.log(
                        "Command not supported or not authorized on {}: '{}'".format(host, cmd))
                    raise CommandError(message="Command not supported or not authorized",
                                       command=cmd,
                                       host=host)

                if result:
                    # logger.info("Connected to {}".format(device))
                    self.connection.emit_message("Connected {}".format(device), log_level=logging.INFO)
                else:
                    if device.last_error_msg:
                        message = device.last_error_msg
                        device.last_error_msg = None
                    else:
                        message = "Connection error"

                    self.connection.log(message)
                    raise ConnectionError(message)  # , host=str(device))

        if device is None:
            raise ConnectionError("No devices")

        return True
355725
function connect() {
    let port = null;

    try {
      port = parseInt(readFileSync(path.join(
        datadir,
        'control-port'
      )).toString().split(':')[1]);
    } catch (err) {
      /* istanbul ignore next */
      portFileReads++;

      /* istanbul ignore next */
      if (portFileReads <= 20) {
        return setTimeout(() => connect(), 1000);
      } else {
        return controller.emit('error',
                               new Error('Failed to read control port'));
      }
    }

    socket.connect(port, '127.0.0.1');
  }
319227
def s_connect(self, server, port, r_server=None):
        
        with self.lock:
            if not r_server:
                self.send('CONNECT %s %s' % (server, port), error_check=True)
            else:
                self.send('CONNECT %s %s %s' % (server, port, \
                                    r_server), error_check=True)
361685
protected function connect()
    {
        $errstr = '';
        $errno  = 0;

        $this->log('creating socket ... ', Net_Notifier_Logger::VERBOSITY_ALL);

        try {
            $this->socket = new Net_Notifier_Socket_Server(
                sprintf(
                    'tcp://0.0.0.0:%s',
                    $this->port
                ),
                null
            );
        } catch (Net_Notifier_Socket_Exception $e) {
            $this->log(
                'failed' . PHP_EOL,
                Net_Notifier_Logger::VERBOSITY_ALL,
                false
            );
            throw $e;
        }

        $this->log('done' . PHP_EOL, Net_Notifier_Logger::VERBOSITY_ALL, false);

        $this->connected = true;
    }
1246503
private function connect()
    {
        if (!$this->isConnected) {
            parent::__construct(
                $this->dsn,
                $this->server->getUsername(),
                $this->server->getPassword(),
                $this->driverOptions
            );
            parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            parent::setAttribute(
                PDO::ATTR_STATEMENT_CLASS,
                [__NAMESPACE__ . '\\' . self::PDO_STATEMENT_CLASS, [$this]]
            );

            $this->isConnected = true;
        }
    }
116224
async def connect(self):
        
        await self._sender.connect(self._connection(
            self.session.server_address,
            self.session.port,
            self.session.dc_id,
            loop=self._loop,
            loggers=self._log,
            proxy=self._proxy
        ))
        self.session.auth_key = self._sender.auth_key
        self.session.save()

        await self._sender.send(self._init_with(
            functions.help.GetConfigRequest()))

        self._updates_handle = self._loop.create_task(self._update_loop())
529101
public function connect()
    {
        $this->isBound = false;
        $this->connection = $this->driver->connect(
            $this->configuration['hostname'],
            $this->configuration['port'],
            $this->configuration['withSSL'],
            $this->configuration['withTLS']
        );

        foreach ($this->configuration['options'] as $key => $value) {
            $this->connection->setOption($key, $value);
        }
    }
869586
public function connect()
    {
        if ( ! ($this->connection = ssh2_connect($this->host, $this->port))) {
            throw new \Exception('Cannot connect to server');
        }
        
        if ( ! ssh2_auth_pubkey_file($this->connection, $this->authUser, $this->authPub, $this->authPriv,
            $this->authPass)
        ) {
            throw new \Exception('Autentication rejected by server');
        }
    }
240885
def connect(self):
        
        # TODO: local_hostname should be configurable
        self.client = smtplib.SMTP(self.options['server'], self.options['port'],
                                   local_hostname='local.domain', timeout=15)
1088310
def connect(self):
        

        count = 1
        no_of_servers = len(self._rabbit_urls)

        while True:
            server_choice = (count % no_of_servers) - 1

            self._url = self._rabbit_urls[server_choice]

            try:
                logger.info('Connecting', attempt=count)
                return pika.SelectConnection(pika.URLParameters(self._url),
                                             self.on_connection_open,
                                             stop_ioloop_on_close=False)
            except pika.exceptions.AMQPConnectionError:
                logger.exception("Connection error")
                count += 1
                logger.error("Connection sleep", no_of_seconds=count)
                time.sleep(count)

                continue
1151151
function connect() {
    if (!redis) {
      debug('createClient ' + key + ' at ' + host + ':' + port);
      redis = redisLib.createClient(port, host, redisOpts); }
  }
1254485
def _connect(self):
        ""
        self.socket = socket.socket()
        self.socket.connect((self.config['host'], self.config['port']))
        self.cmd("NICK %s" % self.config['nick'])
        self.cmd("USER %s %s bla :%s" %
                (self.config['ident'], self.config['host'], self.config['realname']))