Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AbrahamR, 7th_zorro, dr_panther, 1 invisible), 702 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Length stored in a Byte #291608
09/26/09 18:09
09/26/09 18:09
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline OP
Junior Member
GorNaKosh  Offline OP
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
While reading the manual I fall over this here:
Originally Posted By: Online Manual
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.
http://www.conitec.net/beta/send_data.htm

How can I manage this - storing as well as reading?

indetify different incomming structs [Re: GorNaKosh] #291995
09/29/09 15:28
09/29/09 15:28
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline OP
Junior Member
GorNaKosh  Offline OP
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
I found a solution for my problem identifying incomming structs. Here is an example (not tested):
Code:
//flags for identify the structs
#define STRUCT_TYPE_A (1<<0)
#define STRUCT_TYPE_B (1<<1)
#define STRUCT_TYPE_C (1<<2)

//our test struct
typedef struct TEST_STRUCT {
     char flags;   //importent: the flag-char have to be the first property
                   //char = 1Byte -> can store 8flags
     var value;    //content of the struct
     char msg[25];
} TEST_STRUCT;

//example for a sending function
void sendingStruct(var reciever, var type, var value, char msg) {
     TEST_STRUCT *newPacket = malloc(sizeof(TEST_STRUCT));
     newPacket.flags = NULL;
     newPacket.flags |= type;
     newPacket.value = value;
     newPacket.msg = msg;
     
     send_struct_id(reciever,newPacket,sizeof(TEST_STRUCT));
     
     wait(-dplay_entrate/16);
     free(newPacket);
}

//example for a recieving function
on_server_event(void *clientBuf, var clientID) {
     
     if(event_type == EVENT_DATA) {
          
          char *tempBuf = clientBuf;
          
          //now tempBuf[0] points to the first byte of the
          //incomming struct - its the flag-property
          //so with this you can check the type
          
          if((tempBuf[0] & STRUCT_TYPE_A) == STRUCT_TYPE_A) {
          error("Type A");
          }

          if((tempBuf[0] & STRUCT_TYPE_B) == STRUCT_TYPE_B) {
          error("Type B");
          }

          if((tempBuf[0] & STRUCT_TYPE_C) == STRUCT_TYPE_C) {
          error("Type C");
          }
     }
}

//test main
void main() {
     
     //if it's a client
     if(connection == CONNECT_CLIENT) {

          //after connecting
          while (dplay_status < 2) { wait(1); }
          
          //sending a test
          sendingStruct(NULL, STRUCT_TYPE_A, 3, "Test!");
     }     

     return;
}


Anyone with other ideas or improvements???
Gor Na Kosh

Last edited by GorNaKosh; 09/29/09 15:32.

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1