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 returns the number of bytes of data sent, or a number less than 0 if the send has failed.
The data sent is not formatted by GameMaker in any way and the receiving devices will get the data as a stream which means you will have to handle it yourself.
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.
network_send_udp_raw(socket, url, port, bufferid, size);
Argument | Type | Description |
---|---|---|
socket | Network Socket ID | The id of the socket to use. |
url | String | The URL or IP to connect to (a string, can be IPv4 or IPv6). |
port | Real | The port to connect to. |
bufferid | Buffer | The buffer to get the data from. |
size | Real | The size (in bytes) of the data. |
network_send_udp_raw(sock, "www.macsweeneygames.com", 6510, buff, buffer_tell(buff));
The above code will send a raw UDP packet to the server defined by the URL on the port 6510. The data is taken from the buffer in the variable buff.