Establishing a Connection with STK
Once you've initialized the AgConnect API, you need to open a connection to the Ansys Systems Tool Kit® (STK®) application by using the AgConOpenSTK() function, which has the following prototype:
int
AgConOpenSTK (
char **context,
char *notUsed,
char *connectName
);
The context argument points to a variable initialized to NULL. The function will return a unique value in the variable used to identify the connection. It is used to communicate low-level information about the connection within the AgConnect API.
The second argument is no longer used. Use the value NULL for this argument.
The connectName argument specifies the details of the connection. Specify the name of the host machine and its port number, separated by a colon (:). The following example shows a common value for connectName:
localhost:5001
The same value for context that is passed here to AgConOpenSTK() along with connectName should be passed to subsequent Connect functions for that particular connection.
AgConOpenSTK returns AgCNoError if successful and AgCError if an error occurs.
Since there can be multiple connections to the STK application, it is important to remember which context argument belongs to which connection.
See the Connect Example File.
The AgConOpenSTK function assumes that either the STK application or ConnectConsole is running with an authentication mode that allows connections from the same machine and user. If your use case requires a different authentication mode, use the AgConOpenSTKEx function. The prototype for this function is as follows:
int
AgConOpenSTKEx (
AgTChar **context,
const AgTChar *pczConnectName,
const AgEConAuthMode authMode,
const AgTChar *clientCertPath,
const AgTChar *clientKeyPath,
const AgTChar *caPath,
const AgTChar *udsDir,
const AgTChar *udsId
);
where AgEConAuthMode is defined as follows:
enum class AgEConAuthMode
{ eEnforceSingleUserLocal = 0, /* Uses WNUA on Windows and UDS on Linux */ eInsecure, eMutualTLS,}
;
The parameters are defined as follows:
| Parameter | Definition |
|---|---|
| connectName | The name of the socket |
| authMode | The authentication mode: 0, eInsecure, or eMutualTLS |
| clientCertPath |
The path to the client certificate file (*.crt) in mTLS mode |
| clientKeyPath | The path to the client private key file (*.key) in mTLS mode |
| caPath | The path to the server certificate of authority file (*.crt) in mTLS mode |
| udsDir | The directory to store the Unix Domain Socket file (optional, Linux only) |
| udsId | An additional identifier to make the UDS filename unique (optional, Linux only) |