This function sends a data "packet" through the network.
The function takes the Network Socket ID to connect through and then you 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 packet.
Packets sent with this function are formatted such that the GameMaker game receiving the data can "split" the packets correctly, and 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.
WARNING You must not mix the use of regular and raw functions in your game, as doing so will cause issues. This means for a connection made with network_connect, you must use network_send_packet, and for network_connect_raw, use network_send_raw.
NOTE This function uses a TCP-like socket (i.e. network_socket_tcp). It may work with other socket types as well, but this isn't guaranteed.
network_send_packet(socket, bufferid, size);
Argument | Type | Description |
---|---|---|
socket | Network Socket ID | The id of the socket to use. |
bufferid | Buffer | The buffer to get the data from. |
size | Real | The size (in bytes) of the data. |
buff = buffer_load("player_save.dat");
network_send_packet(sock, buff, buffer_get_size(buff));
The above code loads previously saved data into a buffer in memory and stores the newly created buffer in the variable buff. This complete buffer is then send as a packet over the network using the socket identified by the variable sock.