Networking

Networking Event

The Networking event is one which will be triggered by any incoming network traffic, and is linked to the Network Functions. This event generates a special DS Map that is exclusive to this event and is stored in the special variable async_load. This DS map will contain different information depending on the type of network event that generated it.

Common Networking Events

The following keys are common to all received network functions and will always be present in the async_load map:

The possible return values for the "type" key can be any of the four constants listed below:

ConstantDescription
network_type_connectThe event was triggered by a connection.
network_type_disconnectThe event was triggered by a disconnection.
network_type_dataThe event was triggered by incoming data.
network_type_non_blocking_connectThe event was triggered by a connection configured as non-blocking (you can use the function network_set_config() for this, or connect using network_connect_async() or network_connect_async_raw()).

Connecting / Disconnecting

When you have an event of the type network_type_connect or network_type_disconnect, the async_load map will have the following additional key:

If the event is of the type network_type_non_blocking_connect, then additionally there will be the following key:

It is worth noting that the Networking Event does not get triggered in clients when the server disconnects, and that neither of the network_type_* events will be triggered in clients when the server they are connected to disconnects, even if the connection is TCP based.

Receiving Data

When you have a network_type_data type event, which signifies that your network has received data, the map created will have the following keys:

NOTE The buffer created is only valid in these events and will be automatically freed when the event is over.

Attempting Connection

If the os_is_network_connected function returns false when using network_connect_active or network_connect_passive, the result is asynchronously returned in this event. The type key in the async_load map will be one of these values:

ConstantDescription
network_type_upThe connection succeeded.
network_type_up_failedThe connection failed.

If the network goes down at any time, this event is triggered again with the type key set to network_type_down.