> For the complete documentation index, see [llms.txt](https://trialkey.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trialkey.gitbook.io/docs/api-reference/methods/connectsock.md).

# ConnectSock

## Description

Makes a connection to a remote host.

{% hint style="info" %}
**Good to know:** You will need to call this method to make a connection.
{% endhint %}

## Remarks

Use the ConnectSock method to connect to a listening socket. In synchronous mode, this method returns a socket handle to the connection made, or INVALID\_SOCKET (-1) if the call fails. If the call failed, use the LastSockErr property to get the error number (these are standard Winsock errors).

If using asynchronous mode (as indicated by the AsyncUseEvent parameter), the developer should use the EventID parameter to send a unique numeric identifier that will be presented in the ConnectionEstablished event, indicating which ConnectSock the event is in response to. If there is an error, the SocketHandle parameter will be equal to -1, and the application should call the LastSockErr property to determine the nature of the error. Note that in async mode the ConnectSock method will always return 0.

| Param          | Description                                                                                                                           |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| Host           | Host to connect to                                                                                                                    |
| Port           | Port to connect on                                                                                                                    |
| StreamType     | One of the SQ\_PROTOCOL constants (SQ\_TCPIP or SQ\_UDP). Default is SQ\_TCPIP.                                                       |
| AdapterNumber  | Specifies which adapter to use. Default is -1, meaning let the system decide which adapter is appropriate.                            |
| ConnectTimeout | Timeout in seconds                                                                                                                    |
| AsyncUseEvent  | Specifies whether to connect asynchronously. If this param                                                                            |
| EventID        | User provided identifier that is used when the ConnectionEstablished event is fired to identify which ConnectSock call it belongs to. |

## Prototype

LONG ConnectSock(CHAR\* Host, long Port, INT StreamType = SQ\_TCPIP, long AdapterNumber = -1, long ConnectTimeout = -1, BOOL AsyncUseEvent = FALSE, long EventID = 0)
