How can I start RTserver as a Windows Service from within an RTclient?

How can I start RTserver as a Windows Service from within an RTclient?

book

Article ID: KB0085497

calendar_today

Updated On:

Products Versions
TIBCO SmartSockets -
Not Applicable -

Description

Resolution:
The following example demonstrates how to write your own Error Callback to launch RTserver as a Windows Service. RTclient discovers that RTserver has gone down. It needs to restart RTserver as a Windows Service. The discovery process is as follows: The RTclient on its next read or write operation discovers that it is no longer connected to the RTserver. What it does at that point is to invoke its Error callback(s). The default Error Callback provided with the system fundementally follows 2 steps:

TipcSrvDestroy (T_IPC_SRV_CONN_WARM);
TipcSrvCreate(T_IPC_SRV_CONN_FULL);

The first step makes sure that the client has cleaned up the old socket at its end, and the second forces it to reconnect to the RTserver. If it trys to connect and the RTserver is not running, then if the 'start_always' qualifier is set then the RTclient trys to start RTserver automatically but as a Windows Process rather than as a Windows Service. To override this default behavior of starting RTserver as a process you can add your own Error Callback that gets invoked before the default, and in that Error Callback you first check the following:

1). See if the RTserver is running.
2). If not you issue the following TutSystem command: TutSystem("net start rtserver");

When your Error Callback exits the RTserver will once again be running as a Windows Service, and the default Error Callback will simply connect to the running RTserver rather than trying to start it. To impliment the above you should add the following code (a new callback) to your RTclient applications.

void T_ENTRY UserErrorCallback (T_IPC_CONN conn, T_IPC_CONN_ERROR_CB_DATA data, T_CB_ARG arg) {
     if (!TipcSrvIsRunning) {
         if (!TutSystem("net start rtserver")) {
                 TutOut("\n rtserver service startup failed. \n);
                 exit(1);
        }
    }
}

In your main you will need to register this callback and set its priority so it gets executed before the default Error Callback.
T_CB UserErrCb;
UserErrCb = TipcSrvErrorCbCreate (UserErrorCallback, NULL);
if (NULL == UserErrCb) {
     /* do your error processing */
}
if (!TutCbSetPriority(UserErrCb, 100)) {
     /* do your error processing */
}

Note: to stop the RTserver Windows Service after your RTclient has disconeccted you can use the TutSystem API to send the command TutSystem("net stop rtserver"); .

Issue/Introduction

How can I start RTserver as a Windows Service from within an RTclient?