Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by rki. 06/18/24 14:13
A simple game ...
by VoroneTZ. 06/18/24 10:50
Face player all the time ...
by bbn1982. 06/18/24 10:25
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
6 registered members (Martin_HH, AndrewAMD, rki, squik, Ayumi, alibaba), 1,154 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 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