LInet::ReadData

#include "ltwrappr.h"

L_INT LInet::ReadData(plRemoteComp, pBuffer, pulBufferLength)

LInet *plRemoteComp;

/* remote computer instance */

L_CHAR * pBuffer;

/* pointer to the data buffer */

L_UINT32 *pulBufferLength;

/* address of length of buffer */

Reads data from a remote computer.

Parameter

Description

plRemoteComp

An instance of the remote computer from which data is being sent.

pBuffer

Address of the buffer to be filled with the read data

pulBufferLength

Address of the variable to be updated with the size of the read data

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

After this function returns, pulBufferLength will be updated with the actual length of read data. This function should only be used if auto process is disabled. You should call this function in response to the LInet::OnDataReady function.

You must initialize the LEADTOOLS Peer-to-Peer DLL using LInet::StartUp before calling this function.

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::EnableAutoProcess, LInet::SendData, LInet::SendBitmap, LInet::SendSound, LInet::Connect, LInet::Close, LInet::ReadData, LInet::ServerInit, LInet::OnDataReady, LInet::StartUp, LInet::ShutDown, Class Members

Example

// The user should derive a class from LInet to support the OnConnect and OnDataReady callback functions
// Suppose it was named as LUserInet
class LUserInetRD : public LInet
{
protected:
   virtual  L_INT OnConnect(LInet *plConnection, L_INT nError);
   virtual  L_INT OnDataReady(LInet *plConnection, L_INT nError, L_VOID *pBuffer, L_UINT32 ulSize);
};
L_INT LInet__ReadDataExample()
{
   L_INT          nRet;
   LUserInetRD    UserInet;
   nRet = UserInet.StartUp();
   if(nRet != SUCCESS)
      return nRet;
   // connect to LEAD.
   nRet = UserInet.Connect("207.238.49.190", 1000);
   if(nRet != SUCCESS)
      return nRet;
   // other operations
   nRet = UserInet.ShutDown();
   if(nRet != SUCCESS)
      return nRet;
   return SUCCESS;
}
L_INT LUserInetRD::OnConnect(LInet *plConnection, L_INT nError)
{
   L_INT nRet = SUCCESS;
   if (nError != SUCCESS)
      return nError;
   // set auto process to False to receive OnDataReady
   if ( !plConnection->IsAutoProcessEnabled())
        nRet = plConnection->EnableAutoProcess(FALSE);
   return nRet;
}
L_INT LUserInetRD::OnDataReady(LInet *plConnection, L_INT nError, L_VOID *pBuffer, L_UINT32 ulSize)
{
   UNREFERENCED_PARAMETER(pBuffer);
   HGLOBAL  hData = NULL;
   L_CHAR * pData;
   L_INT    nRet = SUCCESS;
   if (nError != SUCCESS)
     return nError;
   hData = GlobalAlloc(GHND, ulSize + 1);
   pData = (L_CHAR *)GlobalLock(hData);
   if ( !pData)
   {
      GlobalUnlock(hData); 
      return FAILURE;
   }
   nRet = ReadData(plConnection, pData, &ulSize);
   pData[ulSize] = 0; // make the data NULL-terminated
   MessageBox(NULL, (L_TCHAR*)pData, TEXT("Data received"), MB_OK);
   GlobalUnlock(hData);
   GlobalFree(hData);
    return nRet;
}