send_data_to (ENTITY*, void* data,var size)
send_data_id (var client_id, void* data,var size)
Sends unspecified data from a client
to the server, or from a server to a certain client or to all clients. The on_server or on_client event
function is triggered on each PC which has received the data. This function can
be used for transferring data packets between server and clients.
Parameters:
ENTITY* - entity pointer, or NULL
for sending to all clients.
client_id - client number as received by the join event or stored in the
struct of a client-created entity.
data - pointer to a buffer that contains the data to be sent.
size - size of the buffer in bytes.
Remarks:
-
On the server the function sends
the data only to the client with the given id resp. the client
that has created the given entity. If NULL is given for the entity
pointer, the server sends the string to all clients.
- When executed on the client, the data is sent to the server and NULL
must be given for the entity pointer.
- The event function on the
receiving PC receives a pointer to the buffer as its first argument.
The buffer is only valid during the event function, and is deallocated
afterwards.
- The buffer size should not exceed about 1000 bytes - data packets
above that size often get lost on transmission over the
Internet. If the length of the
buffer is not known to the client, it can be stored in a byte, short,
or long at the beginning of the buffer,
and then interpreted by the client.
Edition:
C
LC Example:
typedef struct MYDATA {
int x;
char c[20];
} MYDATA;
...
MYDATA* mydata = { x = 1; c = "Test!"; }
// sending data
send_data_to(NULL,mydata,sizeof(MYDATA));
//receiving data
function on_client_event(void* buffer)
{
if (event_type == EVENT_DATA)
memcpy(mydata,buffer,sizeof(MYDATA));
}
See also:
send_var_to,
send_string_to,
on_server,
on_client
► latest
version online