network_send_udp

This function sends data over the network using UDP to a server.

The function takes the Network Socket ID to connect through, the URL to connect to and the port to use. You must then supply the Buffer which contains the data to be sent (for more information on buffers see Reference - Buffers) and finally the size (in bytes) of the data.

The function will return the number of bytes of data sent, or a number less than 0 if the send has failed. It is worth noting that the final size of the data being sent that is returned by this function will also include the GameMaker header information, which is an additional 12 bytes.

UDP is "connectionless" in that you don't actually do a connect, you just send a packet directly to an IP, and the server gets incoming data from an IP address and has to deal with it "as is".

NOTE This function will not work when used in a project running on the HTML5 target, and neither will HTML5 projects be able to receive UDP.

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

 

Syntax:

network_send_udp(socket, url, port, bufferid, size);

ArgumentTypeDescription
socketNetwork Socket IDThe id of the socket to use.
urlStringThe URL or IP to connect to (a string, can be IPv4 or IPv6).
portRealThe port to connect to.
bufferidBufferThe buffer to get the data from.
sizeRealThe size (in bytes) of the data.

 

Returns:

Real

 

Example:

network_send_udp(sock, "www.macsweeneygames.com", 6510, buff, buffer_tell(buff));

The above code will send a UDP packet to the server defined by the URL on the port 6510. The data is taken from the buffer in the variable buff.