network_connect

This function sends a request to connect to a server.

It takes the Network Socket ID to connect through (see network_create_socket) and requires you to give the IP address to connect to (a string, can be IPv4 or IPv6) as well as the port to connect through. If the connection fails a value of less than 0 will be returned.

The connection uses a special protocol that ensures only GameMaker games connect to each other, however if you need to connect to a server that is not a GameMaker game, you can use network_connect_raw.

Note that by default the function is synchronous, so your game may appear to "hang" as the connection is made. You can set a timeout value for connection, or alternatively make the creation asynchronous, using the function network_set_config, or alternatively use the function network_connect_async instead.

NOTE You cannot use this function on HTML5. For WebSockets, use the Async function.

NOTE This function uses a TCP-like socket (i.e. network_socket_tcp). It may work with other socket types as well, but this isn't guaranteed.

 

Syntax:

network_connect(socket, url, port);

ArgumentTypeDescription
socketNetwork Socket IDThe id of the socket to use.
urlStringThe URL or IP to connect to (a string).
portRealThe port to connect to.

 

Returns:

Real or Network Socket ID

 

Example:

client = network_create_socket(network_socket_tcp);
network_connect(client, "192.134.0.1", 6510);

The above code will create a new TCP socket then attempt to connect through that to the given IP address on port 6510.