Learn how to store license files on a database with LicenseSpring's tutorial. Explore best practices for secure and efficient license file management.
Floating Cloud License Tutorial: Step-by-Step Guide
LicenseSpring allows the application developers to issue licenses with concurrent usage, where LicenseSpring acts as the floating license server. This tutorial provides a basic introduction to utilizing the floating cloud, including registering and deregistering a floating cloud license, timeouts, and license borrowing.
For this tutorial, we will be creating an application that checks for an available floating license, uses any available floating license, and maintains control of the license until the user decides to close the program. This guide will mention and provide code snippets from the code, as well as link the source code for the application.
You can find our introduction to working with floating licenses here.
Here is a sample C++ console program that demonstrates how to use floating licenses.
Here are the main points we will discuss in this tutorial:
- Register and Deregister
- Timeout
- License Borrowing
Register and Deregister
Register
Unlike floating server, for a floating cloud license, you will need to activate the floating license on each device that intends to use that license. Thus, when configuring your floating cloud license, it is highly recommended to set "Max activations" equal to or greater than the "Max simultaneous license users" field, as each registered user, will needs to be activated. Once activated, registering from the SDK is very simple, you can either use the dedicated register method, or run an online check. Both will register you to the floating cloud license.
1
2
auto license = licenseManager->getCurrentLicense();
license->registerFloatingLicense(); //Or you can use license->check();
Using the register method will allow you to see how many different license users are concurrently using the floating license at any time.
Deregister
Since there are a limited number of registration spots, it is important to return those registration spots when they're not being used. You will need to deregister a license, so that another user can register their license on their device.
Similar to registering a floating license, there are also multiple ways to deregister/release a license.
You can manually deregister a device from a floating license within your code.
1
2
3
4
//The parameter used in our deregister method, determines whether this method will throw
//exceptions or not. Turning it off (false) is useful, in case we deregister, but we
//weren't originally registered, so nothing will happen.
license->releaseFloatingLicense( false );
Or you can use the auto-release feature. This feature will make it so that whenever your license object is destroyed, then the floating license is automatically released from the device. This is useful, as on application close or crash, the license will be destroyed, and will be automatically released. By default, this is already turned on within the SDK.
1
2
3
4
5
6
7
//You can use the parameter to manually turn on/off the auto release feature.
license->setAutoRelease( true ):
//If you're not sure whether auto release is currently set within your code you can use:
if( license->isAutoReleaseSet() )
{
//do something
}
Finally, the last solution is to let the floating license timeout.
Timeout
The floating timeout (set in minutes) dictates how long the floating license can stay on a device before it requires re-registering. If a device does not register within that time interval, it times out, and its floating license will be returned to the pool for others to use. This helps guarantee all users are (somewhat) concurrently using the license.
To tell if a license has been timed out or deregistered, you can use the expiration field in the local license file. For a floating license, being expired can mean 3 things. You are using a time-limited license and it has run out, you are using a trial license and it has run out, or you are currently deregistered/timed out. This final feature is exclusive to floating licenses, and can be used to check if a license is currently registered or not. Note: this also applies to floating server licenses.
You can use any previous methods to register a floating license to re-register that same license. For some programs this can work, but it requires manually running checks/register API calls from within the code. For example, if the developer programs each feature within their code to run an online check, and if a user doesn't use any features within a certain amount of time, they will be timed out and their license will be returned to the pool. However, there is another more useful method that can be used to set up a background thread that will run continuously on an interval and run online checks.
1
void setupLicenseWatchdog( LicenseWatchdogCallback callback, uint32_t timeout = 0 )
This will create a background thread that will periodically perform online checks (which will reset your floating timeout interval). The parameter timeout dictates when online checks will be done (in minutes).
For a floating license with a floating timeout of “x” minutes, when a floating license is re-registered, their timeout clock will be reset to 0, and they will have another “x” minutes to use that license or re-register again.
License Borrowing
An efficient solution to checking out a license for longer than the default floating timeout is license borrowing. Standard floating licenses need to be checked/renewed within the floating timeout interval. License borrowing allows you to create a license that will show up on the floating server as "used", but the actual borrower can use that license offline until their borrowing period is over. This borrowing can be set to much longer periods than a license’s normal floating timeout period which makes it particularly useful for offline floating licensing. For example, say an employee needs to work on a project requiring a floating license from home but will not have access to their license server due to security constraints. They can borrow a license for 24 hours, which will allow them to use the license without connecting to the server for those 24 hours.
Here's how to borrow using the SDK:
1
2
3
4
5
license->borrow( hours, days );
//You can also set the date on which your borrowed license will be expired.
//Borrow end date time in format "%Y-%m-%dT%H:%M:%SZ", for example "2022-05-28T15:30:00Z
std::string expirydate;
license->borrow( expirydate );
Like registered licenses, borrowed licenses can be deregistered the same way to return the registration spot into the license pool.
To learn more about license borrowing see: License borrowing - Documentation (licensespring.com).
Conclusion
In this tutorial, we went through the basics of a floating cloud license, including how to register/deregister/borrow a license. We also learned how the timeout period works, and how to counteract it. With this knowledge, you should be able to create the appropriate floating license you want for your project, and implement it into your code.