L_InetSendData

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

L_INT EXT_FUNCTION L_InetSendData(hComputer, pBuffer, pulBufferLength, uDataType)

L_COMP hComputer;

/* handle of remote computer */

L_CHAR L_FAR * pBuffer;

/* pointer to the data buffer to send */

L_UINT32 L_FAR * pulBufferLength;

/* address of a variable to be updated with the length of the buffer */

L_UINT uDataType;

/* data type */

Sends data to a remote computer.

Parameter

Description

hComputer

Handle of remote computer to which data will be sent

pBuffer

Pointer to the buffer that contains the data to send

pulBufferLength

Address of a variable that contains the length of buffer, and which will be updated with the amount of data actually sent.

uDataType

Value indicating the type of data being sent. This value determines the type of headers added to the data. Possible values are:

 

Value

Meaning

 

IDATA_IMAGE

[0x0000] image data

 

IDATA_MMEDIA

[0x0001] multimedia object

 

IDATA_USER1

[0x0002] user data

 

IDATA_USER2

[0x0003] user data

 

IDATA_USER3

[0x0004] user data

 

IDATA_USER4

[0x0005] user data

 

The receiving computer will receive the appropriate notification in the INETCALLBACK function as follows:

 

On Send:

On Receive:

 

IDATA_IMAGE

INET_IMAGE_RECEIVED

 

IDATA_MMEDIA

INET_MMEDIA_RECEIVED

 

IDATA_USER1

INET_USER1_RECEIVED

 

IDATA_USER2

INET_USER2_RECEIVED

 

IDATA_USER3

INET_USER3_RECEIVED

 

IDATA_USER4

INET_USER4_RECEIVED

 

Note: If an error occurs during sending or receiving and the headers become corrupted, then the receiving computer will receive the INET_USER1_RECEIVED notification. This means that to differentiate your own user-defined data from bad frames, you can use IDATA_USER2, IDATA_USER3 or IDATA_USER4.

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 amount of data that was actually sent. If pulBufferLength is less than the original value, then the rest of the data is queued, and will be sent at a later time. You do not need to re-send the data.

Note:

With this function, LEADTOOLS adds its own headers to the data being sent. These headers need to be stripped by the remote computer, in order for the actual data to be processed. The remote computer can set auto process by calling L_InetAutoProcess in order for the headers to be stripped.

You must initialize the LEADTOOLS Internet 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_InetSendRawData, L_InetConnect, L_InetClose, L_InetReadData, L_InetSendBitmap, L_InetSendSound, L_InetAutoProcess, L_InetServerInit, L_InetClearQueue, L_InetGetQueueSize, L_InetStartUp, L_InetShutDown

Topics:

Internet Functions

Example

L_COMP hComp; /* handle of the remote computer */
L_INT nRet;

L_INT L_EXPORT EXT_CALLBACK InetCallback(L_COMP hComp,
L_INT nMessage, L_INT nError, L_CHAR L_FAR *pBuffer,
L_UINT32 lSize, L_VOID L_FAR*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 */
nRet = L_InetConnect("server_address", 1000, &hComp, InetCallback, NULL);
if(nRet != SUCCESS)
   MessageBox(NULL, TEXT("Error attempting to connect"), TEXT("ERROR"), MB_OK);

L_INT L_EXPORT EXT_CALLBACK InetCallback(L_COMP hComp,
L_INT nMessage, L_INT nError, L_CHAR L_FAR *pBuffer,
L_UINT32 lSize, L_VOID L_FAR*pUserData)
{
   L_TCHAR L_FAR*pData;
   L_UINT32 lDataSize;

   switch(nMessage)
   {
      case INET_CONNECT:
         /* check the status and send some data */
         if(nError == SUCCESS)
         {
            pData = TEXT("Some Data");
            lDataSize = lstrlen(pData);

            /* now you can assume you are connected to computer 'hComp'
            nRet = L_InetSendData(hComp, pData, &lDataSize, IDATA_USER1);
            /* we can close the connection without data loss with a graceful connection. The closing is delayed until after all the data has been sent. remove the next line if you want to keep the connection open */
            L_InetClose
(hComp, TRUE);
         }
         else
            MessageBox(NULL, TEXT("You have failed to connect!"), TEXT("Error"), MB_OK);
      break;
   }
   return SUCCESS;
}