Even_data question

Posted By: Beker

Even_data question - 03/25/10 20:01

I need to send two types of different "struct" in my network code, how do I recognise inside "EVEN_DATA", which of the two "struct" commands I have recieved up to this point, I have not seen any example of of either.
Posted By: SchokoKeks

Re: Even_data question - 03/25/10 21:57

that is a very good question, I'm interested in the answer too.
Posted By: Beker

Re: Even_data question - 03/28/10 11:15

nobody knows??????????????? crazy
Posted By: Razoron

Re: Even_data question - 03/28/10 11:27

I don't know if this works, but maybe like this:
Code:
typedef struct MYDATA1 {
  int x;
  char c[20];
} MYDATA;
typedef struct MYDATA2 {
  int x;
  int y;
  char c[20];
} MYDATA2;
... 
MYDATA1* mydata1 = { x = 1; c = "Test!"; }
MYDAT21* mydata2 = { x = 1; y = 1; c = "Test!"; }
 
// sending data
send_data_to(NULL,mydata,sizeof(MYDATA1));
 
//receiving data
function on_client_event(void* buffer) 
{
  if (event_type == EVENT_DATA)
    if(sizeof(buffer)==sizeof(MYDATA1))
      ....
    if(sizeof(buffer)==sizeof(MYDATA2))
      ....
}


Posted By: Beker

Re: Even_data question - 04/21/10 09:13

This idea has a problem, if all structs have the same size can not differentiate.
Posted By: Dark_samurai

Re: Even_data question - 04/21/10 12:22

You could use ANet for this. If you send a struct with ANet, it is automatically updated on the receiver. If you want to see if the struct has changed, just send an event after you updated the struct or you could save the content of the struct and check if the content has changed.

Visit: http://www.anet-plugin.com for further informations. The Manual should give you an idea of how a struct can be sent (enet_send_data() is the function you are looking for).
Posted By: fastlane69

Re: Even_data question - 05/17/10 03:31

Wouldn't this do?


Code:
Code:typedef struct MYDATA1 {
  bool dirty;
  int x;
  char c[20];
} MYDATA;
typedef struct MYDATA2 {
  bool dirty;
  int x;
  int y;
  char c[20];
} MYDATA2;
... 
MYDATA1* mydata1 = { dirty = 0,x = 1; c = "Test!"; }
MYDAT21* mydata2 = { dirty =0, x = 1; y = 1; c = "Test!"; }
 
// sending data
mydata1.dirty=1;
send_data_to(NULL,mydata,sizeof(MYDATA1));
 
//receiving data
function on_client_event(void* buffer) 
{
  if (event_type == EVENT_DATA)
    if(Mydata1.dirty == 1)
    {
       Do_Something_Dirty1();
       mydata1.dirty =0;
    }
      ....
       if(Mydata2.dirty == 1)
    {
       Do_Something_Dirty2();
       mydata2.dirty =0;
    }
...

}


© 2024 lite-C Forums