Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 28, 2005, 10:14:48 PM (18 years ago)
Author:
patrick
Message:

The NetworkSocket now uses a real network protocol: packet size is read out dynamicaly: therefore the NetworkStream now has an internal state that
checks if its reading header or body data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/network_protocol.cc

    r5805 r5809  
    4141  /* set the class id for the base object */
    4242  this->setClassID(CL_NETWORK_PROTOCOL, "NetworkProtocol");
    43   this->headerLength = HEADER_LENGTH;
     43  this->headerLength = sizeof(Header);
    4444}
    4545
     
    6565  printf("NetworkProtocol: create header length = %i, bufferLength = %i\n", length, bufferLength);
    6666  //If there isn't enough space for the header return -1
    67   if (length + headerLength > bufferLength)
     67  if (length + this->headerLength > bufferLength)
    6868    return -1;
    6969
     
    7171//     printf("send byte[%i]=%u\n", i, data[i]);
    7272
     73
    7374  //Create space for the header
    7475  for( int i = length - 1; i >= 0; i--)
    75     data[i + headerLength] = data[i];
     76    data[i + this->headerLength] = data[i];
    7677
    77   //Include header
     78  //Now create the header
     79  /* protocol identifier */
    7880  data[0] = 255;
    79   return length + headerLength;
     81  /* version number */
     82  data[1] = 0;
     83  /* sender ID: FIXME: there will be a better ID (for example unique:D)*/
     84  data[2] = (byte)source.getClassID();
     85  /* receiver ID */
     86  data[3] = remoteID;
     87  /* data length*/
     88  data[4] = length;
     89
     90
     91  return length + this->headerLength;
    8092}
    8193
     
    100112  //Extract header
    101113  Header h;
     114  //&h = data;
     115
    102116  h.protocol = data[0];
     117  /* version number */
     118  h.version = data[1];
     119  /* sender ID: FIXME: there will be a better ID (for example unique:D)*/
     120  h.senderID = data[2];
     121  /* receiver ID */
     122  h.receiverID = data[3];
     123  /* data length*/
     124  h.length = data[4];
    103125
    104   h.length = length - headerLength;
    105   h.data = data;
    106126
    107127//   for(int i = 0; i < length; i++)
     
    109129
    110130  //Remove header
    111   for (int i = headerLength; i < length; i++)
    112     data[i - headerLength] = data[i];
     131//   for (int i = headerLength; i < length; i++)
     132//     data[i - headerLength] = data[i];
    113133
    114134  return h;
Note: See TracChangeset for help on using the changeset viewer.