Changeset 6139 in orxonox.OLD for trunk/src/lib/network/network_protocol.cc
- Timestamp:
- Dec 16, 2005, 6:45:32 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/network_protocol.cc
r5822 r6139 57 57 * @arg bufferLength: the length of the internal buffer 58 58 * @arg source: reference to the source Synchronizeable object 59 * @arg remoteID: id number of the remote Synchronizeable object60 59 * @return: the new data length with header (the header data is included into byte* data) 61 60 * -1 if there isn't enough space in the buffer for the header 62 61 */ 63 int NetworkProtocol::createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source , unsigned int remoteID)62 int NetworkProtocol::createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source) 64 63 { 65 printf("NetworkProtocol:create header length = %i, bufferLength = %i\n", length, bufferLength);64 PRINTF(5)("create header length = %i, bufferLength = %i\n", length, bufferLength); 66 65 //If there isn't enough space for the header return -1 67 66 if (length + this->headerLength > bufferLength) 68 67 return -1; 69 68 70 // for(int i = 0; i < length; i++)71 // printf("send byte[%i]=%u\n", i, data[i]);72 69 73 74 //Create space for the header 70 // FIXME: without move Create space for the header 75 71 for( int i = length - 1; i >= 0; i--) 76 72 data[i + this->headerLength] = data[i]; 77 73 78 74 //Now create the header 79 /* protocol identifier */80 data[0] = 255;81 /* version number */82 data[1] = 0;83 75 /* 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; 76 data[0] = (byte)(source.getUniqueID()); 87 77 /* data length*/ 88 data[ 4] = length;78 data[1] = length; 89 79 90 80 … … 100 90 Header NetworkProtocol::extractHeader(byte* data, int length) 101 91 { 102 PRINTF( 0)("extract Header\n");92 PRINTF(5)("extract Header\n"); 103 93 //Test if received data can contain a header 104 94 if (length < headerLength) 105 95 { 106 PRINTF( 0)("Received data is to short; it can't contain a header!");96 PRINTF(1)("Received data is to short; it can't contain a header!\n"); 107 97 Header h; 108 h. protocol= 0;98 h.length = 0; 109 99 return h; 110 100 } … … 114 104 //&h = data; 115 105 116 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]; 106 /* unique ID */ 107 h.synchronizeableID = data[0]; 123 108 /* data length*/ 124 h.length = data[ 4];109 h.length = data[1]; 125 110 126 127 // for(int i = 0; i < length; i++)128 // printf("recS byte[%i]=%u\n", i, data[i]);129 130 //Remove header131 // for (int i = headerLength; i < length; i++)132 // data[i - headerLength] = data[i];133 111 134 112 return h;
Note: See TracChangeset
for help on using the changeset viewer.