L_InetAttachToSocket

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

L_INT EXT_FUNCTION L_InetAttachToSocket(phComputer, hSocket, pfnCallback, pUserData)

L_COMP L_FAR * phComputer;

/* address of a variable to update */

SOCKET hSocket;

/* handle to an existing windows socket */

INETCALLBACK pfnCallback;

/* pointer to a callback function */

L_VOID L_FAR * pUserData;

/* user defined callback data */

Attaches a computer to an existing Windows socket.

Parameter

Description

phComputer

Address of the variable to be updated with the handle of the computer attached to hSocket.

hSocket

Handle of an existing windows socket. After this call, both the computer and socket can be used to send and receive data.

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 L_FAR *. 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

This function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function will allow you to attach to an existing Windows Socket. (See the Windows SDK for the socket command for more explanation on Windows Sockets). When the computer handle is no longer needed, use L_InetDetachFromSocket to detach from the socket. Calling L_InetDetachFromSocket will close hComputer, but will leave the socket useable (L_InetClose does not need to be called for the computer handle). Do not call L_InetClose unless both the computer handle and the windows socket need to be closed.

If the function is successful, any notifications for this socket are redirected to pfnCallback.

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_InetClose, L_InetDetachFromSocket, L_InetSendRawData, L_InetSendData, L_InetGetQueueSize, L_InetClearQueue

Topics:

Sending Commands and Responses

 

A Client-Server Diagram: Sending Commands and Responses

Example

// this example will create a socket of type datagrams

#include <winsock2.h>
SOCKET hSocket;
SOCKADDR_IN sin;
L_COMP hComputer;

/* create the socket */
hSocket = socket (AF_INET, SOCK_DGRAM, 0);

// set your callback in here

sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr("207.238.49.190");
sin.sin_port = htons(1000);

connect(hSocket, (LPSOCKADDR) &sin ,sizeof(sin));

L_InetAttachToSocket(&hComputer, hSocket, NULL, NULL);

// do the things you need…

// detach from the socket when you don’t need to use the LEADTOOLS functions anymore
L_InetDetachFromSocket(hComputer, TRUE, &hSocket);

// restore your callback for the socket…
// delete the socket
shutdown(hSocket, SD_BOTH);

// close the socket
closesocket(hSocket);