I'm not having success in the receipt of characters (char*), using the function ("send_data");
Below is an example of how I'm trying:
On Server:
typedef struct MYDATA {
int id;
char name[20];
} MYDATA;
MYDATA* mydata = { id = 0; name = ""; }
function server_event(STRING* name, var idd)
{
if (event_type == EVENT_JOIN)
{
//send_data for all Clients
mydata.name="Mike";
mydata.id=10;
send_data_to(NULL,mydata,sizeof(MYDATA));
}
}
In the example described above, I Sending a data packet to all Clients
The data packet sends a whole number ("ID") and a sequence of characters ("name")
>Now I'll describe how I'm working on the "Client" to receive this data packet
On Clients:
typedef struct MYDATA {
int id;
char name[20];
} MYDATA;
STRING* mystring = "";
TEXT* tMessage = { string(mystring); flags |= SHOW; layer = 1; pos_x = 10; pos_y = 50; font = "arial#16b"; }
MYDATA* mydata = { id = 0; name = ""; }
function client_event(void* buffer)
{
if(event_type == EVENT_DATA){
memcpy(mydata,buffer,sizeof(MYDATA));
str_cat((tMessage.pstring)[0],str_for_num(NULL,mydata.id));
str_cat((tMessage.pstring)[0]," / ");
str_cat((tMessage.pstring)[0],mydata.name);
}
}
There are the practical examples that show how I am sending a data packet from the server to the client, and also how I'm getting this information into Client.
In testing what happens is:
The value (int id) is being sent and received successfully
But I'm not having the same success with the data (char* name)
When I go to print on screen the result of the data packet received, the value (int id) is correct, but the value (char * name) is not correct. It comes empty or comes with a lot of unknown characters .
Can anyone help me?