L_InetConnect
#include "l_bitmap.h"
#include "ltnet.h"
L_LTNET_API L_INT L_InetConnect(pszAddress, nPort, phComputer, pfnCallback, pUserData)
L_CHAR * pszAddress; |
/* address of the computer to which to connect */ |
L_INT nPort; |
/* port on remote computer to which to connect */ |
L_COMP * phComputer; |
/* address of variable to update */ |
INETCALLBACK pfnCallback; |
/* pointer to a callback function */ |
L_VOID *pUserData; |
/* user defined callback data */ |
Connects to a remote computer.
Parameter |
Description |
pszAddress |
Character string containing the address of the computer to which you want to connect |
nPort |
Port on the remote computer to which to connect |
phComputer |
Address of variable to be updated with the handle of the connected computer |
pfnCallback |
Pointer to a callback function of type INETCALLBACK for receiving messages for phComputer. Use the function pointer to your callback function as the value of this parameter. |
pUserData |
Void pointer that you can use to pass one or more additional parameters that the callback function needs. |
|
To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure. |
|
If the additional parameters are not needed, you can pass NULL in this parameter. |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
This function requests a connection to a remote computer. The remote computer must accept the connection by calling L_InetAcceptConnect.
If the connection is successful phComputer is updated with the handle to the connected computer. phComputer can then be used with the other internet functions that require a handle to a computer.
pszAddress can be any URL or an IP address in the Internet dot notation. Ex. http://www.leadtools.com or 207.238.49.130.
The INETCALLBACK function will be called when a connection request is successfully accepted by the remote computer.
Immediately after successfully connecting to a LEADTOOLS server started with L_InetServerInit, the INETCALLBACK function will be called. If auto process is enabled, the message will be INET_USER1_RECEIVED and pBuffer will contain a NULL terminated string containing "LEAD Technologies Server X.X" where X.X is the server version number. If auto process is not enabled, the message will be INET_DATA_READY, and the version string can be read using L_InetReadData.
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
Example
L_INT EXT_CALLBACK InetCallback(L_COMP hComp, L_INT nMessage, L_INT nError, L_CHAR * pBuffer, L_UINT32 lSize, L_VOID* pUserData) { UNREFERENCED_PARAMETER(pBuffer); UNREFERENCED_PARAMETER(lSize); UNREFERENCED_PARAMETER(pUserData); L_TCHAR s[100]; /* set up a buffer to retrieve the name of the server */ L_SIZE_T sizeof_s = sizeof(s); /* the size of s */ switch(nMessage) { case INET_CONNECT: /* check the status and try to get server's name */ if(nError == SUCCESS) { /* now you can assume you are connected to computer 'hComp' */ if(L_InetGetHostName(hComp, (L_CHAR*) s, HOST_NAME_IP, &sizeof_s) == SUCCESS) { MessageBox(NULL, TEXT("You have successfully connected to"), s, MB_OK); } /* do whatever you want to do with the server here ... */ /* 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; } L_INT InetConnectExample(L_COMP hComp) { L_INT nRet; /* 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("207.238.49.190", 1000, &hComp, (INETCALLBACK) InetCallback, NULL); if(nRet != SUCCESS) { MessageBox(NULL, TEXT("Error attempting to connect"), TEXT("ERROR"), MB_OK); return nRet; } return SUCCESS; }