code: def try_connect(self):
      
      sock = RecvBufferedSocket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
      try:
        sock.connect(self._address)
      except (socket.error, socket.gaierror) as e:
        logger.debug('Encountered socket exception {!r} when attempting connect to nailgun'.format(e))
        sock.close()
        raise self.NailgunConnectionError(
          address=self._address_string,
          pid=self._maybe_last_pid(),
          pgrp=self._maybe_last_pgrp(),
          wrapped_exc=e,
        )
      else:
        return sock
docs: Creates a socket, connects it to the nailgun and returns the connected socket.
  
      :returns: a connected `socket.socket`.
      :raises: `NailgunClient.NailgunConnectionError` on failure to connect.