Changeset 6139 in orxonox.OLD for trunk/src/subprojects
- Timestamp:
- Dec 16, 2005, 6:45:32 PM (19 years ago)
- Location:
- trunk/src/subprojects/network
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/subprojects/network/Makefile.am
r5996 r6139 11 11 network_LDADD = $(MAINSRCDIR)/lib/network/libORXnet.a \ 12 12 \ 13 $(MAINSRCDIR)/lib/ tinyxml/libtinyxml.a13 $(MAINSRCDIR)/lib/parser/tinyxml/libtinyxml.a 14 14 15 15 network_SOURCES= network_unit_test.cc \ -
trunk/src/subprojects/network/network_unit_test.cc
r5996 r6139 11 11 #include "network_stream.h" 12 12 #include "synchronizeable.h" 13 #include "converter.h" 13 14 14 15 #include "simple_sync.h" … … 40 41 server.listen(9999); 41 42 42 NetworkSocket client1(ip);43 44 NetworkSocket server1 = server.getNewSocket();45 46 NetworkSocket client2(ip);47 48 NetworkSocket server2 = server.getNewSocket();43 NetworkSocket* client1 = new NetworkSocket(ip); 44 45 NetworkSocket* server1 = server.getNewSocket(); 46 47 NetworkSocket* client2 = new NetworkSocket(ip); 48 49 NetworkSocket* server2 = server.getNewSocket(); 49 50 50 51 char buf[1024]; 51 52 52 53 printf("read from client1 before sending data\n"); 53 printf("result: %d bytes\n", client1 .readPacket((byte*)buf, 1024));54 printf("result: %d bytes\n", client1->readPacket((byte*)buf, 1024)); 54 55 55 56 printf("read from client2 before sending data\n"); 56 printf("result: %d bytes\n", client2 .readPacket((byte*)buf, 1024));57 printf("result: %d bytes\n", client2->readPacket((byte*)buf, 1024)); 57 58 58 59 int n; … … 61 62 char * str3 = "client2 to server"; 62 63 char * str4 = "server2 to client"; 63 n = client1 .writePacket((byte*)str1, strlen(str1)+1);64 n = client1->writePacket((byte*)str1, strlen(str1)+1); 64 65 printf("%d bytes send from client1\n", n); 65 n = server1 .writePacket((byte*)str2, strlen(str2)+1);66 n = server1->writePacket((byte*)str2, strlen(str2)+1); 66 67 printf("%d bytes send from server1\n", n); 67 n = client2 .writePacket((byte*)str3, strlen(str3)+1);68 n = client2->writePacket((byte*)str3, strlen(str3)+1); 68 69 printf("%d bytes send from client2\n", n); 69 n = server2 .writePacket((byte*)str4, strlen(str4)+1);70 n = server2->writePacket((byte*)str4, strlen(str4)+1); 70 71 printf("%d bytes send from server2\n", n); 71 72 SDL_Delay(1000); 72 73 73 74 printf("read from server1\n"); 74 n = server1 .readPacket((byte*)buf, 1024);75 n = server1->readPacket((byte*)buf, 1024); 75 76 printf("read %d bytes\n", n); 76 77 if (n<0) … … 80 81 81 82 printf("read from server2\n"); 82 n = server2 .readPacket((byte*)buf, 1024);83 n = server2->readPacket((byte*)buf, 1024); 83 84 printf("read %d bytes\n", n); 84 85 if (n<0) … … 88 89 89 90 printf("read from client1\n"); 90 n = client1 .readPacket((byte*)buf, 1024);91 n = client1->readPacket((byte*)buf, 1024); 91 92 printf("read %d bytes\n", n); 92 93 if (n<0) … … 96 97 97 98 printf("read from client2\n"); 98 n = client2 .readPacket((byte*)buf, 1024);99 n = client2->readPacket((byte*)buf, 1024); 99 100 printf("read %d bytes\n", n); 100 101 if (n<0) … … 106 107 107 108 printf("try to send more than 255 bytes\n"); 108 printf("result: %d\n", client1 .writePacket((byte*)buf, 1000));109 110 server1 .writePacket((byte*)str1, strlen(str1)+1);109 printf("result: %d\n", client1->writePacket((byte*)buf, 1000)); 110 111 server1->writePacket((byte*)str1, strlen(str1)+1); 111 112 SDL_Delay(500); 112 113 printf("try to read with a too small buffer\n"); 113 printf("result: %d\n", client1 .readPacket((byte*)buf, strlen(str1)));114 printf("result: %d\n", client1->readPacket((byte*)buf, strlen(str1))); 114 115 115 116 return 0; … … 190 191 Synchronizeable* ss = new SimpleSync("Server\0"); 191 192 192 netMan->createServer( *ss,port);193 netMan->createServer(/**ss, */port); 193 194 SDL_Delay(20); 194 195 … … 196 197 { 197 198 netMan->synchronize(); 198 SDL_Delay( 500);199 SDL_Delay(1000); 199 200 } 200 201 … … 229 230 Synchronizeable* ss = new SimpleSync("Client\0"); 230 231 231 netMan->establishConnection( ip, *ss);232 netMan->establishConnection((const char*)"localhost", port/*,ip, *ss*/); 232 233 233 234 for(;;) … … 280 281 delete ss; 281 282 283 return 0; 284 } 285 286 287 int converter(int argc, char** argv) 288 { 289 int x = 200564786; 290 printf("To convert: %i\n", x); 291 byte* res = Converter::intToByteArray(x); 292 for (int i = 0; i < 4; i++) 293 printf("%i ", res[i]); 294 printf("\n"); 295 296 int z = Converter::byteArrayToInt(res); 297 298 printf("ReConvert: %i\n", z); 299 300 301 //float a = 5.4f; 302 //float b = 2.0f; 303 //printf("%f mod %f = %f", a, b, a % b); 304 305 printf("\n"); 306 307 float y; 308 char* s; 309 310 y = 12.0f; 311 s = Converter::floatToBinString(y); 312 printf("%f = ", y); 313 printf(s); printf("\n"); 314 315 y = 24549026.0f; 316 s = Converter::floatToBinString(y); 317 printf("%f = ", y); 318 printf(s); printf("\n"); 319 320 y = 12.4e20f; 321 s = Converter::floatToBinString(y); 322 printf("%f = ", y); 323 printf(s); printf("\n"); 324 325 y = 4.7824f; 326 s = Converter::floatToBinString(y); 327 printf("%f = ", y); 328 printf(s); printf("\n"); 329 330 331 282 332 return 0; 283 333 } … … 308 358 else if (! strcmp( "--listen", argv[i]) || !strcmp("-l", argv[i])) 309 359 return startListen(argc, argv); 360 else if (! strcmp( "--converter", argv[i]) || !strcmp("-o", argv[i])) 361 return converter(argc, argv); 310 362 } 311 363 -
trunk/src/subprojects/network/read_sync.cc
r5996 r6139 80 80 * read data from Synchronizeable 81 81 */ 82 int ReadSync::readBytes(byte* data )82 int ReadSync::readBytes(byte* data, int maxLength, int * reciever) 83 83 { 84 84 return 0; -
trunk/src/subprojects/network/read_sync.h
r5996 r6139 17 17 18 18 virtual void writeBytes(const byte* data, int length); 19 virtual int readBytes(byte* data );19 virtual int readBytes(byte* data, int maxLength, int * reciever); 20 20 21 21 -
trunk/src/subprojects/network/simple_sync.cc
r5996 r6139 86 86 * read data from Synchronizeable 87 87 */ 88 int SimpleSync::readBytes(byte* data )88 int SimpleSync::readBytes(byte* data, int maxLength, int * reciever) 89 89 { 90 90 PRINTF(0)("SimpleSync: sent %i bytes of data\n", this->outLength); -
trunk/src/subprojects/network/simple_sync.h
r5996 r6139 17 17 18 18 virtual void writeBytes(const byte* data, int length); 19 virtual int readBytes(byte* data );19 virtual int readBytes(byte* data, int maxLength, int * reciever); 20 20 21 21 -
trunk/src/subprojects/network/write_sync.cc
r5996 r6139 86 86 * read data from Synchronizeable 87 87 */ 88 int WriteSync::readBytes(byte* data )88 int WriteSync::readBytes(byte* data, int maxLength, int * reciever) 89 89 { 90 90 PRINTF(0)("WriteSync: sent %i bytes of data\n", this->outLength); -
trunk/src/subprojects/network/write_sync.h
r5996 r6139 17 17 18 18 virtual void writeBytes(const byte* data, int length); 19 virtual int readBytes(byte* data );19 virtual int readBytes(byte* data, int maxLength, int * reciever); 20 20 21 21
Note: See TracChangeset
for help on using the changeset viewer.