SocketTools .NET Edition

Class Initialization

When you begin developing your application using SocketTools .NET, the first thing that must happen is the class instance must be initialized. The initialization method serves two purposes. It loads the networking libraries required to establish a connection and it validates the runtime license key that you provide. The runtime license key is a string of characters which identifies your license to use and redistribute SocketTools. It is unique to your product serial number and must be used when redistributing your application to an end-user.

Creating an instance of the class with your runtime license key can be accomplished in one of two ways, depending on personal preferences and the design of your application. The simplest approach, and one familiar to developers who have used the SocketTools ActiveX control, is to explicitly call the Initialize method in your code. The other more advanced approach is to define the RuntimeLicense attribute for the assembly that is referencing the class. This attribute is set in the AssemblyInfo.vb or AssemblyInfo.cs module that is part of the project. For more information on specific usage, refer to the Technical Reference.

Developers who are evaluating SocketTools will not have a runtime license key and must pass an empty string to the Initialize method. This will enable that instance of the class to load on the development system during the evaluation period, but will prevent component from being redistributed to an end-user until a license has been purchased.

If you install the product with a serial number, the runtime license key will be automatically created for you during the installation process. If you have installed an evaluation copy of SocketTools and then purchased a license, the license key can be created using the License Manager utility that was included with the product. Simply select the License | Header File menu option and select the programming language that you are using.

The runtime license key is normally stored in the Include folder where you installed SocketTools and is defined in a file named SocketToolsLicense which can be included with your application. For example, C# programmers would use the SocketToolsLicense.cs header file while Visual Basic programmers would use the SocketToolsLicense.vb module. The Visual Basic module would define the runtime license key as:

[VisualBasic]
'
' SocketTools 11 Build 2218
' Copyright 2025 Catalyst Development Corporation
' All rights reserved
'
' This file is licensed to you pursuant to the terms of the
' product license agreement included with the original software
' and is protected by copyright law and international treaties.
'
Public Const SocketToolsLicenseKey As String = ""

This could either be included with your Visual Basic.NET application or you could simply copy the string into your application. The class could then be initialized like this:

[VisualBasic]
'
' Initialize the control using the specified runtime license key;
' if the key is not specified, the development license will be used
'
If Socket.Initialize(SocketToolsLicenseKey) = False Then
    MsgBox("Unable to initialize SocketTools component")
End If

A return value of true indicates that the class was initialized successfully. A return value of false indicates that the class could not be initialized with the specified runtime license key. The LastError property will contain the error code that indicates the exact cause of the error.

An application is only required to call the Initialize method once, but it must be called for each instance of the class that is created. It is safe to call the initialization method more than once, but for each time that it is called, you must call the Uninitialize method for that class before your program terminates. In other words, if you called Initialize at the beginning of your program, you must call Uninitialize before your program ends. The Uninitialize method performs any necessary housekeeping operations, such as returning memory allocated for the class back to the operating system. If there are any open connections at the time that the Uninitialize method is called, they will be aborted. After the class has been uninitialized, you must call the Initialize method again before setting any properties or calling any methods in that instance of the class.