L_InetReadData

#include "l_bitmap.h"
#include "ltnet.h"

L_LTNET_API L_INT L_InetReadData(hComputer, pBuffer, pulBufferLength)

L_COMP hComputer;

/* handle of remote computer */

L_CHAR * pBuffer;

/* pointer to the data buffer */

L_UINT32 * pulBufferLength;

/* address of length of buffer */

Reads data from a remote computer.

Parameter

Description

hComputer

Handle 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 INET_DATA_READY message, in the INETCALLBACK function.

You must initialize the LEADTOOLS Peer-to-Peer DLL using L_InetStartUp 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:

L_InetAutoProcess, L_InetSendData, L_InetSendBitmap, L_InetSendSound, L_InetConnect, L_InetClose, L_InetReadData, L_InetServerInit, INETCALLBACK, L_InetStartUp, L_InetShutDown

Topics:

Peer-to-Peer Functions

Example

static L_INT EXT_CALLBACK InetCallback(L_COMP   hComp,
                                       L_INT    nMessage,
                                       L_INT    nError,
                                       L_CHAR * pBuffer,
                                       L_SIZE_T lSize,
                                       L_VOID* pUserData);
/* note: instead of server_address you need to put the IP address
of the computer running the server. You can also put in
the computer name, if the server is running on a local network */
/* you do not need to use MakeProcInstance for 32 bit applications */
 L_INT InetReadDataExample(L_COMP hComp /* handle of the remote computer */)
{
   L_INT nRet;
   nRet = L_InetConnect("server_address", 1000, &hComp, InetCallback, NULL);
   if(nRet != SUCCESS)
   {
      MessageBox(NULL, TEXT("Error attempting to connect"), TEXT("ERROR"), MB_OK);
      return nRet;
   }
   return SUCCESS;
}
/*
sometime before closing down the program call L_InetClose(hComp, TRUE)
*/
static L_INT EXT_CALLBACK InetCallback(L_COMP   hComp,
                                 L_INT    nMessage,
                                 L_INT    nError,
                                 L_CHAR * pBuffer,
                                 L_SIZE_T lSize,
                                 L_VOID* pUserData)
{
   UNREFERENCED_PARAMETER(pBuffer);
   UNREFERENCED_PARAMETER(pUserData);
   L_INT nRet;
   HGLOBAL hData;
   L_CHAR * pData;
   L_UINT32 uSize; 
   switch(nMessage)
   {
      case INET_CONNECT:
         /* check the status and send some data */
         if(nError == SUCCESS)
         {
            /* set auto process to False to receive INET_DATA_READY */
            L_InetAutoProcess(hComp, FALSE);
         }
         else
            MessageBox(NULL, TEXT("You have failed to connect!"), TEXT("Error"), MB_OK);
         break;
      case INET_DATA_READY:
         /* Note: most servers (including a LEAD server started with L_InetServerInit 
            will send some form of data right after connection) */
         if(nError == SUCCESS)
         {
            hData = GlobalAlloc(GHND, lSize + 1);
            pData = (L_CHAR *)GlobalLock(hData);
            if(pData)
            {
               uSize = (L_UINT32)lSize; 
               nRet = L_InetReadData(hComp, pData, &uSize);
               pData[lSize] = 0; /* make the data NULL-terminated */
               MessageBox(NULL, (L_TCHAR*)pData, TEXT("Data received"), MB_OK);
               GlobalUnlock(hData);
            }
            GlobalFree(hData);
         break;
         }
   }
   return SUCCESS;
}