network_set_config(config_value, setting);

参数 描述
config_value The config value constant to set (listed below).
setting The setting of the config value.

返回: String(字符串)


With this function you can set different network configurations. These configurations are given as constants and the setting will depend on the constant that you have chosen. The table below lists the available constants and their settings:

常量 描述 设定
network_config_connect_timeout 设置单次连接的超时数 以毫秒为单位
network_config_use_non_blocking_socket 告知GameMaker Studio 2不要阻止连接 0 = 阻止, 1 = 不阻止
network_config_enable_reliable_udp Enables the "reliable UDP" protocol for an existing UDP socket 以毫秒为单位
network_config_disable_reliable_udp Disables the "reliable UDP" protocol for an existing UDP socked. 0 = 阻止, 1 = 不阻止

The first option (network_config_connect_timeout) simply sets the timeout for connecting to a server but doesn't change connection behaviour apart from the time you have to wait. It is recommended that you don't set this too low and keep it at about 1000 for a LAN only game or 4000 or so for internet, or the game may fail to connect randomly. If you wish to set a timeout value for sending/receiving packets then use the function network_set_timeout().

The second option (network_config_use_non_blocking_socket) means that the network connect functions will all return a socket_id instantly, but you can't send or receive on that socket until you've received an async network event. The event triggered will have the "type" key set to network_type_non_blocking_connect (you can find further details from the page on the Networking Asynchronous Event). This is a global setting as GameMaker Studio 2 does not support a mixture of blocking and non-blocking in one application.

The third and fourth options (network_config_enable_reliable_udp, network_config_disable_reliable_udp) are for enabling or disabling the GameMaker Studio 2 reliable UDP protocol and as such, should only be used with UDP connections. What "reliable" in this case this means is that, when enabled on both ends of a connection, GameMaker Studio 2 will attempt to check your packets have arrived correctly and re-send any that don't arrive (note, we do not guarantee in your packets will arrive in order of transmission). When using a reliable socket type, there will be a 12-byte header added to all udp packets which contains information needed by GameMaker Studio 2 to check the packet for errors and re-send missing packets.


network_set_config(network_config_connect_timeout, 1000);
network_set_config(network_config_use_non_blocking_socket, 1);

上述代码会设置网络连接超时限制为1000毫秒并告知GameMaker Studio 2不阻止连接。