Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7613 in orxonox.OLD for branches/network/src


Ignore:
Timestamp:
May 13, 2006, 4:21:53 PM (19 years ago)
Author:
rennerc
Message:

subprojects/network can test handshake now

Location:
branches/network/src
Files:
7 edited

Legend:

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

    r7602 r7613  
    5959
    6060  this->setSynchronized(true);
    61   PRINTF(5)("Handshake created clientId = %d\n", clientId);
     61  PRINTF(0)("Handshake created clientId = %d\n", clientId);
    6262}
    6363
  • branches/network/src/lib/network/network_stream.cc

    r7602 r7613  
    369369      peers[clientId].handshake->setUniqueID(clientId);
    370370      peers[clientId].userId = clientId;
     371     
     372      PRINTF(0)("num sync: %d\n", synchronizeables.size());
    371373    }
    372374
  • branches/network/src/lib/network/udp_server_socket.cc

    r7570 r7613  
    3333    bOk = false;
    3434  }
     35 
     36  memset( packet->data, 0, UDP_PACKET_SIZE );
     37  PRINTF(0)("PACKET DATA: %x\n", packet->data);
    3538 
    3639  listen( port );
  • branches/network/src/lib/network/udp_socket.cc

    r7570 r7613  
    3737  this->packet = SDLNet_AllocPacket( UDP_PACKET_SIZE );
    3838 
     39  assert( this->packet );
     40 
     41  memset( packet->data, 0, UDP_PACKET_SIZE );
     42  PRINTF(0)("PACKET DATA: %x\n", packet->data);
     43 
    3944  this->connectToServer( host, port );
    4045}
  • branches/network/src/subprojects/network/network_unit_test.cc

    r7565 r7613  
    1414#include "synchronizeable.h"
    1515#include "converter.h"
     16#include "state.h"
     17#include "shared_network_data.h"
    1618
    1719#include "simple_sync.h"
     
    244246int startServer(int argc, char** argv)
    245247{
    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);
    255253
    256254  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 
    260263  SDL_Delay(20);
    261264
     
    264267    netMan->synchronize();
    265268    SDL_Delay(1000);
     269    ss->debug();
    266270  }
    267271
     
    276280int startClient(int argc, char** argv)
    277281{
     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
     313int startListen(int argc, char** argv)
     314{
    278315  if( argc < 3)
    279316  {
    280317    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");
    283320    return 0;
    284321  }
     
    294331
    295332  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");
    336334
    337335  netMan->establishConnection( name, port );
  • branches/network/src/subprojects/network/simple_sync.cc

    r6634 r7613  
    3131  : Synchronizeable()
    3232{
    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" ) );
    5036}
    5137
     
    5642SimpleSync::~SimpleSync()
    5743{
    58   if( this->outData)
    59     delete[] this->outData;
    60   if( this->inData)
    61     delete[] this->inData;
     44}
     45
     46void SimpleSync::debug( )
     47{
     48  printf("IN: %d OUT: %d\n", in, out);
    6249}
    6350
    6451
    65 /**
    66  *  write data to Synchronizeable
    67  */
    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");
    7452
    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 Synchronizeable
    87  */
    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() const
    105 {
    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() const
    116 {
    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  
    1515    SimpleSync(const char* name);
    1616    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();
    2019
    2120
    2221  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;
    3325  };
    3426
Note: See TracChangeset for help on using the changeset viewer.