Connect or reconnect to broker
433196
def reconnect_to_broker(self):
        """"""
        #print "CONNECT !"
        if self.client:
            self.poller.unregister(self.client)
            self.client.close()
        self.client = self.ctx.socket(zmq.DEALER)
        self.client.linger = 0
        self.client.connect(self.broker)
        self.poller.register(self.client, zmq.POLLIN)
        if self.verbose:
            logging.info("I: connecting to broker at %s...", self.broker)
148928
def on_api_socket_reconnected(self):
        """"""
        self.__is_acc_sub_push = False
        self.__last_acc_list = []

        ret, msg = RET_OK, ''
        # auto unlock trade
        if self._ctx_unlock is not None:
            password, password_md5 = self._ctx_unlock
            ret, data = self.unlock_trade(password, password_md5)
            logger.debug('auto unlock trade ret={},data={}'.format(ret, data))
            if ret != RET_OK:
                msg = data

        # 定阅交易帐号推送
        if ret == RET_OK:
            self.__check_acc_sub_push()

        return ret, msg
53901
def addBrokerList(self, aBrokerInfoList):
        """"""
        self.cluster_available.update(set(aBrokerInfoList))

        # If we need another connection to a fellow broker
        # TODO: only connect to a given number
        for aBrokerInfo in aBrokerInfoList:
            self.cluster_socket.connect(
                "tcp://{hostname}:{port}".format(
                    hostname=aBrokerInfo.hostname,
                    port=aBrokerInfo.task_port,
                )
            )
            self.cluster.append(aBrokerInfo)
840709
async def reconnect(self):
        """"""
        _LOGGER.debug('starting Connection.reconnect')
        await self._connect()
        while self._closed:
            await self._retry_connection()
        _LOGGER.debug('ending Connection.reconnect')
165911
function connectIfNeeded() {
      // console.log('re-establishing the connect');
      websocket = null;
      socketCreationInProcess = false;

      // The token may have expired so test for it.
      getToken(determineService())
        .then(() => {
          return processSTTSocketStart(false);
        })
        .then(() => {
          //return Promise.resolve();
          return;
        })
        .catch((err) => {
          //return Promise.resolve();
          return;
        });
    }
1367789
function _connectHandler(self) {
      return function() {
        // Assign
        var connection = this;

        // Pool destroyed stop the connection
        if (self.state === DESTROYED || self.state === DESTROYING) {
          return connection.destroy();
        }

        // Clear out all handlers
        handlers.forEach(function(event) {
          connection.removeAllListeners(event);
        });

        // Reset reconnect id
        self.reconnectId = null;

        // Apply pool connection handlers
        connection.on('error', connectionFailureHandler(self, 'error'));
        connection.on('close', connectionFailureHandler(self, 'close'));
        connection.on('timeout', connectionFailureHandler(self, 'timeout'));
        connection.on('parseError', connectionFailureHandler(self, 'parseError'));

        // Apply any auth to the connection
        reauthenticate(self, this, function() {
          // Reset retries
          self.retriesLeft = self.options.reconnectTries;
          // Push to available connections
          self.availableConnections.push(connection);
          // Set the reconnectConnection to null
          self.reconnectConnection = null;
          // Emit reconnect event
          self.emit('reconnect', self);
          // Trigger execute to start everything up again
          _execute(self)();
        });
      };
    }
332753
def a_return_and_reconnect(ctx):
    """"""
    ctx.ctrl.send("\r")
    ctx.device.connect(ctx.ctrl)
    return True
1368308
def reconnect_account(self):
        
        url = self.reconnect_url
        result = self.get(url)
        return result
56916
async def _connect(self, connection_lost_callbk=None):
        """"""
        self.connection_lost_callbk = connection_lost_callbk
        url = self._config['url']
        LOG.info("Connecting to ElkM1 at %s", url)
        scheme, dest, param, ssl_context = parse_url(url)
        conn = partial(Connection, self.loop, self._connected,
                       self._disconnected, self._got_data, self._timeout)
        try:
            if scheme == 'serial':
                await serial_asyncio.create_serial_connection(
                    self.loop, conn, dest, baudrate=param)
            else:
                await asyncio.wait_for(self.loop.create_connection(
                    conn, host=dest, port=param, ssl=ssl_context), timeout=30)
        except (ValueError, OSError, asyncio.TimeoutError) as err:
            LOG.warning("Could not connect to ElkM1 (%s). Retrying in %d seconds",
                        err, self._connection_retry_timer)
            self.loop.call_later(self._connection_retry_timer, self.connect)
            self._connection_retry_timer = 2 * self._connection_retry_timer \
                if self._connection_retry_timer < 32 else 60
247642
def reinit(self):
        
        log.debug("Reinitializing socket connection for %s:%d" % (self.host, self.port))

        if self._sock:
            self.close()

        try:
            self._sock = socket.create_connection((self.host, self.port), self.timeout)
        except socket.error:
            log.exception('Unable to connect to kafka broker at %s:%d' % (self.host, self.port))
            self._raise_connection_error()
530786
function doReconnect() {
    //
    // Cleanup and recreate the socket associated
    // with this instance.
    //
    self.retry.waiting = true;
    self.socket.removeAllListeners();
    self.socket = common.createSocket(self._options);

    //
    // Cleanup reconnect logic once the socket connects
    //
    self.socket.once('connect', function () {
      self.retry.waiting = false;
      self.retry.retries = 0;
    });

    //
    // Attempt to reconnect the socket
    //
    self._setup();
    self.connect();
  }
232546
def reconnect(url=nil, user=nil, pass=nil, opts={})
    @connection_pool.disconnect!
    connect(url, user, pass, opts)
  end
847503
async def _reconnect(self):
        

        # 1. Close all transactions
        for msg_class in self._transactions:
            _1, _2, _3, coroutine_abrt, _4 = self._msgs_registered[msg_class]
            if coroutine_abrt is not None:
                for key in self._transactions[msg_class]:
                    for args, kwargs in self._transactions[msg_class][key]:
                        self._loop.create_task(coroutine_abrt(key, *args, **kwargs))
            self._transactions[msg_class] = {}

        # 2. Call on_disconnect
        await self._on_disconnect()

        # 3. Stop tasks
        for task in self._restartable_tasks:
            task.cancel()
        self._restartable_tasks = []

        # 4. Restart socket
        self._socket.disconnect(self._router_addr)

        # 5. Re-do start sequence
        await self.client_start()
107286
def failedToGetPerspective(self, why, broker):
        
        log.msg("ReconnectingPBClientFactory.failedToGetPerspective")
        # put something useful in the logs
        if why.check(pb.PBConnectionLost):
            log.msg("we lost the brand-new connection")
            # fall through
        elif why.check(error.UnauthorizedLogin):
            log.msg("unauthorized login; check worker name and password")
            # fall through
        else:
            log.err(why, 'While trying to connect:')
            reactor.stop()
            return

        # lose the current connection, which will trigger a retry
        broker.transport.loseConnection()
373755
function Broker(options) {
  EventEmitter.call(this);
  this._exchange = null;
  this._queues = {};
  this._ctags = {};
  
  this._options = options;
}
1354616
function reconnect() {
  client.end(false, function () {
    console.log('Reconnecting client: ' + clientId);
    client.connect(url, { 'clientId': clientId });
  });
}
1128519
def _reconnected(self):
        """"""

        if self._login_data or self._login_token:

            def reconnect_login_callback(error, result):
                if error:
                    if self._login_token:
                        self._login_token = None
                        self._login(self._login_data,
                                    callback=reconnect_login_callback)
                        return
                    else:
                        raise MeteorClientException(
                            'Failed to re-authenticate during reconnect')

                self.connected = True
                self._resubscribe()

            if self._login_token:
                self._resume(self._login_token,
                             callback=reconnect_login_callback)
            else:
                self._login(self._login_data,
                            callback=reconnect_login_callback)
        else:
            self._resubscribe()