This function is used to create a new client socket for your game to communicate over the network. You must define the socket type (see the list of constants below) and the function will return a unique id for that socket, which should be used in all further function calls for that socket, or a value of less than 0 if the connection fails.
NOTE: You can use the IP "127.0.0.1" to connect back to the same device that is running the game.
| Constant | Description |
|---|---|
| network_socket_tcp | Create a socket using TCP. |
| network_socket_udp | Create a socket using UDP. |
| network_socket_ws | Create a web socket (only for projects running on HTML5), using TCP. |
| network_socket_bluetooth | Create a bluetooth socket (currently unavailable!). |
network_create_socket(type);
| Argument | Description |
|---|---|
| type | The type of socket connection to create (see the constants listed below). |
Real
if os_browser == browser_not_a_browser
{
client = network_create_socket(network_socket_tcp);
network_connect( client, "192.134.0.1", 6510 );
}
else
{
client = network_create_socket(network_socket_ws);
network_connect( client, "192.134.0.1", 6520 );
}
The above code will check whether the game is running in a browser or not and create a new TCP or Web socket before attempting to connect through that to the given IP address on the given port.