# ConnectSocket

## Description

Creates a socket and attempts to connect to the specified IP address. This will create a TCP connection that you can then use to send and receive data. This command will return immediately and connect in the background, you should use GetSocketConnected to check if the socket connects successfully or fails. You should give a timeout value that is long enough for the socket to connect, typically 3000 milliseconds is a good value, but high latency connections might need longer. If the connection times out then this command will return 0. The port number must match the listening port of the device you are connecting to.
This works slightly differently when exported to HTML5, it uses a WebSocket which sends an HTTP style header and requires an HTTP style response to connect.

## Definition

integer ConnectSocket( socketID, szIP, port, timeout )

int agk::ConnectSocket( UINT socketID, const char *szIP, int port, int timeout )

integer ConnectSocket( szIP, port, timeout )

UINT agk::ConnectSocket( const char *szIP, int port, int timeout )

## Parameters

- socketID - An ID to use to reference this socket later
- szIP - The IP address to connect to, this can be IPv4 or IPv6
- port - The TCP port to connect to, in the range 1025 to 65535
- timeout - The time in milliseconds to wait before aborting the connection attempt