Changeset 7613 in orxonox.OLD for branches/network
- Timestamp:
- May 13, 2006, 4:21:53 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/handshake.cc
r7602 r7613 59 59 60 60 this->setSynchronized(true); 61 PRINTF( 5)("Handshake created clientId = %d\n", clientId);61 PRINTF(0)("Handshake created clientId = %d\n", clientId); 62 62 } 63 63 -
branches/network/src/lib/network/network_stream.cc
r7602 r7613 369 369 peers[clientId].handshake->setUniqueID(clientId); 370 370 peers[clientId].userId = clientId; 371 372 PRINTF(0)("num sync: %d\n", synchronizeables.size()); 371 373 } 372 374 -
branches/network/src/lib/network/udp_server_socket.cc
r7570 r7613 33 33 bOk = false; 34 34 } 35 36 memset( packet->data, 0, UDP_PACKET_SIZE ); 37 PRINTF(0)("PACKET DATA: %x\n", packet->data); 35 38 36 39 listen( port ); -
branches/network/src/lib/network/udp_socket.cc
r7570 r7613 37 37 this->packet = SDLNet_AllocPacket( UDP_PACKET_SIZE ); 38 38 39 assert( this->packet ); 40 41 memset( packet->data, 0, UDP_PACKET_SIZE ); 42 PRINTF(0)("PACKET DATA: %x\n", packet->data); 43 39 44 this->connectToServer( host, port ); 40 45 } -
branches/network/src/subprojects/network/network_unit_test.cc
r7565 r7613 14 14 #include "synchronizeable.h" 15 15 #include "converter.h" 16 #include "state.h" 17 #include "shared_network_data.h" 16 18 17 19 #include "simple_sync.h" … … 244 246 int startServer(int argc, char** argv) 245 247 { 246 if( argc <= 2) 247 { 248 printf(" Wrong arguments try following notations:\n"); 249 printf(" --server [port number]\n"); 250 return 0; 251 } 252 253 int port = atoi(argv[2]); 254 printf("Starting Server on port %i\n", port); 248 249 250 State::setOnline(true); 251 SharedNetworkData::getInstance()->setGameServer( true ); 252 printf("Starting Server on port %i\n", 9999); 255 253 256 254 NetworkManager* netMan = NetworkManager::getInstance(); 257 Synchronizeable* ss = new SimpleSync("Server\0"); 258 259 netMan->createServer(/**ss, */port); 255 256 netMan->initialize(); 257 258 netMan->createServer(/**ss, */ 9999); 259 260 SimpleSync* ss = new SimpleSync("Server\0"); 261 262 260 263 SDL_Delay(20); 261 264 … … 264 267 netMan->synchronize(); 265 268 SDL_Delay(1000); 269 ss->debug(); 266 270 } 267 271 … … 276 280 int startClient(int argc, char** argv) 277 281 { 282 283 284 State::setOnline(true); 285 NetworkManager* netMan = NetworkManager::getInstance(); 286 287 288 netMan->initialize(); 289 290 291 292 netMan->establishConnection("localhost", 9999); 293 294 SimpleSync* ss = new SimpleSync("SimpleSync\0"); 295 netMan->connectSynchronizeable( *ss ); 296 297 for(;;) 298 { 299 netMan->synchronize(); 300 SDL_Delay(1000); 301 ss->debug(); 302 } 303 304 305 delete netMan; 306 delete ss; 307 308 return 0; 309 } 310 311 312 313 int startListen(int argc, char** argv) 314 { 278 315 if( argc < 3) 279 316 { 280 317 printf(" Wrong arguments try following notations:\n"); 281 printf(" -- client[server ip] [port number]\n");282 printf(" -- client[server name] [port number]\n");318 printf(" --listen [server ip] [port number]\n"); 319 printf(" --listen [server name] [port number]\n"); 283 320 return 0; 284 321 } … … 294 331 295 332 NetworkManager* netMan = NetworkManager::getInstance(); 296 Synchronizeable* ss = new SimpleSync("Client\0"); 297 298 netMan->establishConnection((const char*)"localhost", port/*,ip, *ss*/); 299 300 for(;;) 301 { 302 netMan->synchronize(); 303 SDL_Delay(500); 304 } 305 306 307 delete netMan; 308 delete ss; 309 310 return 0; 311 } 312 313 314 315 int startListen(int argc, char** argv) 316 { 317 if( argc < 3) 318 { 319 printf(" Wrong arguments try following notations:\n"); 320 printf(" --listen [server ip] [port number]\n"); 321 printf(" --listen [server name] [port number]\n"); 322 return 0; 323 } 324 325 char* name = argv[2]; 326 int port = atoi(argv[3]); 327 printf("Connecting to %s, on port %i\n", name, port); 328 329 IPaddress ip; 330 int error = SDLNet_ResolveHost(&ip, name, port); 331 if(error == -1) 332 printf("\n\nerror on address resolution, program inconsistancy\n\n"); 333 334 NetworkManager* netMan = NetworkManager::getInstance(); 335 Synchronizeable* ss = new ReadSync("WriteSync\0"); 333 Synchronizeable* ss = new SimpleSync("SimpleSync\0"); 336 334 337 335 netMan->establishConnection( name, port ); -
branches/network/src/subprojects/network/simple_sync.cc
r6634 r7613 31 31 : Synchronizeable() 32 32 { 33 /* define the local buffer size */ 34 this->outLength = 10; 35 this->recLength = 0; 36 this->inLength = 40; 37 this->outData = new byte[this->outLength]; 38 this->inData = new byte[this->inLength]; 39 40 /* init the buffer data */ 41 for( int i = 0; i < this->outLength; i++) 42 { 43 this->outData[i] = i; 44 } 45 for( int i = 0; i < this->inLength; i++) 46 { 47 this->inData[i] = 0; 48 } 49 33 in = 0; 34 out = 1; 35 id = registerVarId( new SynchronizeableInt( &in, &out, "var" ) ); 50 36 } 51 37 … … 56 42 SimpleSync::~SimpleSync() 57 43 { 58 if( this->outData) 59 delete[] this->outData; 60 if( this->inData) 61 delete[] this->inData; 44 } 45 46 void SimpleSync::debug( ) 47 { 48 printf("IN: %d OUT: %d\n", in, out); 62 49 } 63 50 64 51 65 /**66 * write data to Synchronizeable67 */68 int SimpleSync::writeBytes(const byte* data, int length, int sender)69 {70 PRINTF(0)("SimpleSync: got %i bytes of data\n", length);71 this->recLength = length;72 if(this->inLength < length)73 PRINTF(0)("ERROR: local buffer is smaller than the data to receive.\n");74 52 75 /* copy the data localy */76 for( int i = 0; i < length; i++)77 {78 this->inData[i] = data[i];79 }80 /* and debug output */81 this->writeDebug();82 }83 84 85 /**86 * read data from Synchronizeable87 */88 int SimpleSync::readBytes(byte* data, int maxLength, int * reciever)89 {90 PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength);91 92 /* debug msg */93 this->readDebug();94 95 /* write the test message */96 for( int i = 0; i < this->outLength; i++)97 data[i] = this->outData[i];98 99 /* return the length of the test */100 return this->outLength;101 }102 103 104 void SimpleSync::writeDebug() const105 {106 PRINTF(0)("Write in bytes: \t(0 <-) |");107 for(int i = 0; i < this->recLength; i++)108 {109 PRINT(0)(" [%u] ",this->inData[i]);110 }111 PRINT(0)("|\n");112 }113 114 115 void SimpleSync::readDebug() const116 {117 PRINTF(0)("Read out bytes: \t(0 ->) |");118 for(int i = 0; i < this->outLength; i++)119 {120 PRINT(0)(" [%u] ",this->outData[i]);121 }122 PRINT(0)("|\n");123 } -
branches/network/src/subprojects/network/simple_sync.h
r6981 r7613 15 15 SimpleSync(const char* name); 16 16 virtual ~SimpleSync(); 17 18 virtual int writeBytes(const byte* data, int length, int sender); 19 virtual int readBytes(byte* data, int maxLength, int * reciever); 17 18 void debug(); 20 19 21 20 22 21 private: 23 virtual void writeDebug() const; 24 virtual void readDebug() const; 25 26 27 private: 28 byte* inData; 29 int inLength; 30 int recLength; 31 byte* outData; 32 int outLength; 22 int in; 23 int out; 24 int id; 33 25 }; 34 26
Note: See TracChangeset
for help on using the changeset viewer.