Changeset 5802 in orxonox.OLD for branches/network/src/lib
- Timestamp:
- Nov 27, 2005, 7:17:56 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_protocol.cc
r5752 r5802 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: Benjamin Wuest … … 63 63 int NetworkProtocol::createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source, unsigned int remoteID) 64 64 { 65 PRINTF(0)("create header\n"); 66 printf("length = %i, bufferLength = %i\n", length, bufferLength); 65 printf("NetworkProtocol: create header length = %i, bufferLength = %i\n", length, bufferLength); 67 66 //If there isn't enough space for the header return -1 68 67 if (length + headerLength > bufferLength) 69 68 return -1; 70 69 71 70 //Create space for the header 72 71 for( int i = length - 1; i >= 0; i--) 73 72 data[i + headerLength] = data[i]; 74 73 75 74 //Include header 76 75 data[0] = 255; 76 return length + headerLength; 77 77 } 78 78 … … 94 94 return h; 95 95 } 96 96 97 97 //Extract header 98 98 Header h; 99 99 h.protocol = data[0]; 100 100 101 101 h.length = length - headerLength; 102 102 h.data = data; 103 103 104 104 //Remove header 105 105 for (int i = headerLength; i < length; i++) 106 106 data[i - headerLength] = data[i]; 107 107 108 108 return h; 109 109 } -
branches/network/src/lib/network/network_stream.cc
r5800 r5802 106 106 107 107 /* send the received data to connectionMonitor */ 108 this->connectionMonitor->processPacket((byte*)downBuffer, ret + sizeof(Header));108 this->connectionMonitor->processPacket((byte*)downBuffer, ret); 109 109 110 this->networkProtocol->createHeader((byte*)downBuffer, ret, DATA_STREAM_BUFFER_SIZE,111 *(this->synchronizeables), 12);110 ret = this->networkProtocol->createHeader((byte*)downBuffer, ret, DATA_STREAM_BUFFER_SIZE, 111 *(this->synchronizeables), 12); 112 112 113 printf("created header: data packet wights: %i bytes\n", ret); 113 114 /* pass the data to the network socket */ 114 ret = this->networkSocket->writeBytes((byte*)downBuffer, PACKAGE_SIZE + sizeof(Header));115 ret = this->networkSocket->writeBytes((byte*)downBuffer, ret); 115 116 /* check if there was an error */ 117 printf("NetworkSocket: sent %i bytes\n", ret); 116 118 if( ret == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");} 117 119 … … 123 125 PRINT(0)("============== UPSTREAM:================\n"); 124 126 /* first of all read data from networkSocket*/ 125 ret = this->networkSocket->readBlock((byte*)upBuffer, PACKAGE_SIZE + sizeof(Header));127 ret = this->networkSocket->readBlock((byte*)upBuffer, 11/* this is very bad: hard coded packet sizes! */); 126 128 /* error checking: data read? */ 127 if( ret != PACKAGE_SIZE + sizeof(Header)) { PRINTF(0)("Error while reading data from the NetworkSocket\n");} 129 printf("NetworkSocket: received %i bytes\n", ret); 130 if( ret != PACKAGE_SIZE + sizeof(Header)) { PRINTF(0)("Error while reading data from the NetworkSocket. Skipping further work\n");} 131 else 132 { 133 /* send the received data to connectionMonitor */ 134 this->connectionMonitor->processPacket((byte*)upBuffer, ret); 128 135 129 /* send the received data to connectionMonitor */130 this->connectionMonitor->processPacket((byte*)upBuffer, PACKAGE_SIZE + sizeof(Header));136 /* extract Header */ 137 this->networkProtocol->extractHeader((byte*) upBuffer , ret); 131 138 132 /* extract Header */ 133 this->networkProtocol->extractHeader((byte*) upBuffer , PACKAGE_SIZE + sizeof(Header)); 134 135 /* now pass the data to the sync object */ 136 this->synchronizeables->writeBytes((byte*)upBuffer, ret); 139 /* now pass the data to the sync object */ 140 this->synchronizeables->writeBytes((byte*)upBuffer, ret); 141 } 137 142 138 143 }
Note: See TracChangeset
for help on using the changeset viewer.