LInet::ResponseCallBack

#include " ltwrappr.h "

virtual L_INT LInet::ResponseCallBack (plConnection, uCommand, uCommandID, nError, nStatus, uParams, pParams, uExtra, pExtra)

LInet * plConnection;

/* instance of a remote computer */

CMDTYPE uCommand;

/* command type */

L_UINT uCommandID;

/* command id */

L_INT nError;

/* status of the received data */

L_INT nStatus;

/* status */

L_UINT uParams;

/* number of parameters */

pPARAMETER pParams;

/* pointer to parameters */

L_UINT uExtra;

/* length */

L_CHAR * pExtra;

/* pointer to extra data */

Notifies a computer that a response has been received.

Parameter

Description

plConnection

Instance of the remote computer from which the command was sent.

uCommand

The command type which prompted this response. For a list of possible values, refer to CMDTYPE.

uCommandID

Command Id. Each command sent by a member of a connection should have a unique ID. Since a member of a connection may send several commands, this ID allows that member to identify when a specific request has been completed.

nError

Determines whether the response was received properly. If not all the parameters were received properly, then nStatus will be set to an error code (most likely ERROR_TRANSFER_ABORTED). Note that this is not the status of the command. This is only an indication of whether this response has been received properly. nStatus indicates whether the command has executed properly or not.

nStatus

Status of the original command. It indicates whether the command has executed properly on the remote end. If the command completes successfully, this should be SUCCESS. Otherwise the value should be one of the Return Codes.

uParams

The number of parameters for this response.

pParams

Pointer to an array of PARAMETER structures that contain the parameters for the response.

uExtra

Length of any extra data sent with the response.

pExtra

Pointer to the extra data sent with the response.

Returns

SUCCESS

This function was successful.

< 1

An occurred. Refer to Return Codes.

Comments

A call to this overridable function is generated when a computer receives a response from a remote computer.

To process responses to commands, a class must be derived from LInet and this member function must be overridden.

Note: The parameters (uParams, pParams) and the extra data (uExtra, pExtra) for this response are not the parameters of the original command! They are only sent if this response needs to send some data to the computer that originally sent the command. An example of a response that needs to send a parameter back is the response for the CMD_CREATE_WIN command. In this case, the response will need to send back the window handle of the newly created window. Most of the responses will only send back the status of the command (nStatus).

The string parameters and pExtra are only valid during this call. Do not free these pointers and dont try to keep references to the strings. If the data is needed outside this function, allocate buffers and copy the data into them.

Required DLLs and Libraries

LTNET

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

LInet::CommandCallBack, LInet::SendRsp, LInet::SendLoadRsp, LInet::SendCreateWinRsp, LInet::SendAttachBitmapRsp, LInet::SendSaveRsp, LInet::SendSizeWinRsp, LInet::SendShowWinRsp, LInet::SendCloseWinRsp, LInet::SendFreeBitmapRsp, LInet::SendSetRectRsp

Topics:

Sending Commands and Responses

 

A Client Server Diagram: Sending Commands and Responses

Example

class LUserNet : public LInet
{
public:
   L_INT  OnConnect(LInet *plConnection, L_INT nError)
   {
      L_INT   nRet = SUCCESS;
      L_CHAR  *pszHostName;
      L_TCHAR strMsg[L_MAXPATH];
      
      if(nError != SUCCESS)
      {
         wsprintf(strMsg, _T("Error[%d]: OnConnect"), nRet);
         MessageBox(NULL, strMsg, 0 , 0);
         return nError;
      }
      
      // Get the remote computer name   
      if ((pszHostName = plConnection->GetHostName(HOST_NAME_IP)) == NULL)      
         return FAILURE;   
      wsprintf(strMsg, _T("OnConnect: Connected to %hs"), (LPTSTR)pszHostName);
      MessageBox(0, strMsg, 0, 0);
      this->SendLoadCmd(plConnection, CMD_LOAD, TEXT("E:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\IMAGE1.CMP"));
      return nRet;
   }
   L_INT ResponseCallBack(LInet*       plConnection,
                          CMDTYPE      uCommand,
                          L_UINT       uCommandID,
                          L_INT        nError,
                          L_INT        nStatus,
                          L_UINT       uParams, 
                          pPARAMETER   pParams, 
                          L_UINT       uExtra,
                          L_CHAR*      pExtra)
   {
      UNREFERENCED_PARAMETER(plConnection);
      UNREFERENCED_PARAMETER(pParams);
      UNREFERENCED_PARAMETER(pExtra);
      L_TCHAR strMsg[_MAX_PATH];
      L_TCHAR* pszString=TEXT("INVALID CMD");
      switch (uCommand)
      {
      case CMD_LOAD:
         pszString = TEXT("CMD_LOAD");
         break;
      case CMD_SAVE:
         pszString = TEXT("CMD_SAVE");
         break;
      case CMD_CREATE_WIN:
         pszString = TEXT("CMD_CREATE_WIN");
         break;
      case CMD_SIZE_WIN:
         pszString = TEXT("CMD_SIZE_WIN");
         break;
      case CMD_CLOSE_WIN:
         pszString = TEXT("CMD_CLOSE_WIN");
         break;
      case CMD_SHOW_WIN:
         pszString = TEXT("CMD_SHOW_WIN");
         break;
      case CMD_SET_RECT:
         pszString = TEXT("CMD_SET_RECT");
         break;
      case CMD_SEND_ANN:
         pszString = TEXT("CMD_SEND_ANN");
         break;
      case CMD_ATTACH_BITMAP:
         pszString = TEXT("CMD_ATTACH_BITMAP");
         break;
      case CMD_FREE_BITMAP:
         pszString = TEXT("CMD_FREE_BITMAP");
         break;
      }
      wsprintf(strMsg, TEXT("Response to %s, id=%d, nError=%d, uParams=%d, nStatus=%d%s received"), 
               pszString, 
               uCommandID, 
               nError, 
               uParams, 
               nStatus, uExtra ? TEXT(", uExtra") : TEXT(""));
      MessageBox(NULL, strMsg, TEXT(""), MB_OK);
      return SUCCESS;
   }
};
L_INT LInet__ResponseCallBackExample()
{
   static LUserNet  Client;
   Client.StartUp();
   L_INT nRet = Client.Connect("127.0.0.1", 1000);
   if(nRet !=SUCCESS)
      return nRet;
   return SUCCESS;
}