LInet::SendCmd

#include " ltwrappr.h "

L_INT LInet::SendCmd (plRemoteComp, uCommand, uCommandID, pInetPacket=NULL)

LInet * plRemoteComp;

/* instance of a remote computer */

CMDTYPE uCommand;

/* command type */

L_UINT uCommandID;

/* command id */

LInetPacket *pInetPacket;

/* pointer to an LlnetPacket object */

Sends a command to a remote computer.

Parameter

Description

plRemoteComp

Instance of the remote computer to which the command will be sent.

uCommand

The command to send. 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 command request has been completed.

pInetPacket

Pointer to an LlnetPacket object containing the parameters for the command. You can pass NULL if the command doesn't need any parameters.

Returns

SUCCESS

This function was successful.

< 1

An occurred. Refer to Return Codes.

Comments

The remote computer should respond by calling LInet::SendRsp in its LInet::CommandCallBack function.

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

Some commands will send back only the commands status (indicating whether the command succeeded or not). But some commands will send back additional information if the command succeeds. For example, responses to LInet::SendLoadCmd will send the bitmap ID while responses to LInet::SendCreateWinCmd will send the window identifier (which can be used to resize or close the window).

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

Funtions:

LInet::SendRsp, LInet::CommandCallBack, LInet::ResponseCallBack, Class Members

Topics:

Sending Commands and Responses

 

A Client Server Diagram: Sending Commands and Responses

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
//This example sends a message to a remote connection to flip a bitmap
//It assumed that: 
//1.  m_Inet is an object of the class LInet. 
//2.  the network as been started (LInet::StartUp())
//3.  a connection has been established with a remote server (LInet::m_Inet.Connect())
//4.  GetNextCommandID() is a function that returns a unique command identifier
//5.  UpdateStatusbar() is a function that displays a message in the status bar
//6.  m_uWindowID is a window id that is received in the LInet::ResponseCallBack() as a result
//    of a call to m_Inet.SendCreateWinCmd()
//7.  m_uBitmapID is a bitmap id that is received in the LInet::ResponseCallBack() as a result
//    of a call to m_Inet.SendLoadCmd()
enum
{
   CMD_FLIP = CMD_USER_CUSTOM,
   CMD_GET,
   CMD_REVERSE,
   CMD_90,
   CMD_180,
   CMD_SHEAR,
   CMD_RESIZE,
   CMD_POSTERIZE,
   CMD_NOISE,
   CMD_OILIFY,
   CMD_RESOLUTION,
   CMD_INVERT,
   CMD_CONTRAST,
   CMD_SATURATION,
   CMD_GAMMA,
   CMD_LOADPATH
};
class LUserNet1 : 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, MAKE_IMAGE_PATH(TEXT("IMAGE1.CMP")));
      return nRet;
   }
   L_INT CommandCallBack (LInet * plConnection,
                          CMDTYPE     uCommand,
                          L_UINT      uCommandID,
                          L_INT       nError,
                          L_UINT      uParams, 
                          pPARAMETER  pParams, 
                          L_UINT      uExtra,
                          L_CHAR*pExtra);
};
LUserNet1 m_ClientInet1;
L_INT LInet__SendCmdExample(LInet * pInetRemoteServer, L_UINT uBitmapID)
{
   L_INT nRet = SUCCESS; 
   CMDTYPE CMD_FLIP;
   CMD_FLIP = (CMDTYPE)0;
   LInetPacket InetPacket(NULL, NULL, "%ud", uBitmapID); 
   nRet = m_ClientInet1.SendCmd(pInetRemoteServer, CMD_FLIP, 1000, &InetPacket); 
   if(nRet != SUCCESS) 
   {
       return nRet;
   }
   return SUCCESS;
}
//The CommandCallBack() is processed on the server
//To process the commands sent to the computer, you must:
//1. Derive a class from LInet
//2. Override the CommandCallBack member function
//
//Assume that 
//1. m_Inet is an object of the class CMyNet (derived from LInet).
//2. the network as been started (LInet::StartUp()) 
//3. a connection has been established with a remote client
//4. UpdateStatusbar() displays a message in the status bar
//5. m_BitmapList maintains a list of LBitmapWindow objects
L_INT LUserNet1::CommandCallBack (LInet * plConnection,
                              CMDTYPE     uCommand,
                              L_UINT      uCommandID,
                              L_INT       nError,
                              L_UINT      uParams, 
                              pPARAMETER  pParams, 
                              L_UINT      uExtra,
                              L_CHAR*pExtra)
{
   UNREFERENCED_PARAMETER(pExtra);
   UNREFERENCED_PARAMETER(uExtra);
   UNREFERENCED_PARAMETER(uParams);
   UNREFERENCED_PARAMETER(pParams);
   UNREFERENCED_PARAMETER(uCommandID);
   UNREFERENCED_PARAMETER(plConnection);
   L_INT nStatus = ERROR_FEATURE_NOT_SUPPORTED;
   if(nError != SUCCESS)
      nStatus = ERROR_TRANSFER_ABORTED;
   else
   {
      switch(uCommand)
      {
         case CMD_FLIP:
         {
            //Add your code here
         } 
         break;
         default: 
         {
            return nStatus; 
         }
      }
   }
   return nStatus;
}