Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5996 in orxonox.OLD for trunk/src/lib/network/network_stream.cc


Ignore:
Timestamp:
Dec 9, 2005, 12:31:01 PM (20 years ago)
Author:
patrick
Message:

orxonox/trunk: merged network branche into trunk with command svn merge -r 5824:HEAD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/network_stream.cc

    r5822 r5996  
    4040
    4141NetworkStream::NetworkStream()
    42   : DataStream()
     42    : DataStream()
    4343{
    4444  this->init();
    4545  /* initialize the references */
     46  this->type = NET_CLIENT;
    4647  this->networkSocket = new NetworkSocket();
    4748  this->networkProtocol = new NetworkProtocol();
     
    5051}
    5152
     53NetworkStream::NetworkStream(IPaddress& address, NodeType type)
     54{
     55  this->type = type;
     56  this->init();
     57  this->networkSocket = new NetworkSocket(address);
     58  this->networkProtocol = new NetworkProtocol();
     59  this->synchronizeables = NULL;
     60  this->connectionMonitor = new ConnectionMonitor();
     61}
     62
     63
     64NetworkStream::NetworkStream(unsigned int port, NodeType type)
     65{
     66  this->type = type;
     67  this->init();
     68  this->networkSocket = new NetworkSocket();
     69//  this->networkSocket->listen(port);
     70  this->networkProtocol = new NetworkProtocol();
     71  this->synchronizeables = NULL;
     72  this->connectionMonitor = new ConnectionMonitor();
     73}
     74
    5275
    5376NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type)
    54   : DataStream()
    55 {
     77    : DataStream()
     78{
     79  this->type = type;
    5680  this->init();
    5781  this->networkSocket = new NetworkSocket(address);
     
    5983  this->synchronizeables = &sync;
    6084  this->connectionMonitor = new ConnectionMonitor();
     85  this->bActive = true;
    6186}
    6287
    6388
    6489NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type)
    65   : DataStream()
    66 {
     90    : DataStream()
     91{
     92  this->type = type;
    6793  this->init();
    6894  this->networkSocket = new NetworkSocket();
    69   this->networkSocket->listen(port);
     95//  this->networkSocket->listen(port);
    7096  this->networkProtocol = new NetworkProtocol();
    7197  this->synchronizeables = &sync;
    7298  this->connectionMonitor = new ConnectionMonitor();
     99  this->bActive = true;
    73100}
    74101
     
    79106  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
    80107  this->state = NET_REC_HEADER;
     108  this->bActive = false;
    81109}
    82110
     
    85113{
    86114
    87  networkSocket->disconnectServer();
    88 
    89  if( this->networkSocket)
    90    delete networkSocket;
    91 
    92  delete connectionMonitor;
    93  delete networkProtocol;
    94 }
     115  networkSocket->disconnectServer();
     116
     117  if( this->networkSocket)
     118    delete networkSocket;
     119
     120  delete connectionMonitor;
     121  delete networkProtocol;
     122}
     123
     124
     125void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
     126{
     127  this->synchronizeables = &sync;
     128  if( this->networkSocket != NULL)
     129    this->bActive = true;
     130}
     131
    95132
    96133void NetworkStream::processData()
     
    102139  PRINT(0)("============= DOWNSTREAM:===============\n");
    103140  /* first of all read the synchronizeable's data: */
    104   dataLength = this->synchronizeables->readBytes((byte*)downBuffer);
    105 
    106   /* send the received data to connectionMonitor */
    107   this->connectionMonitor->processPacket((byte*)downBuffer, dataLength);
    108 
    109   dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE,
    110       *(this->synchronizeables), 12/* some random number (no real id)*/);
    111 
    112   /* pass the data to the network socket */
    113   dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength);
    114   /* check if there was an error */
    115   if( dataLength == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");}
    116 
     141  if( this->isServer())
     142    dataLength = this->synchronizeables->readBytes((byte*)downBuffer);
     143
     144  if( dataLength > 0)
     145  {
     146    /* send the received data to connectionMonitor */
     147    this->connectionMonitor->processPacket((byte*)downBuffer, dataLength);
     148
     149    dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE,
     150                 *(this->synchronizeables), 12/* some random number (no real id)*/);
     151
     152    /* pass the data to the network socket */
     153 //   dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength);
     154    /* check if there was an error */
     155    if( dataLength == -1)
     156    {
     157      PRINTF(0)("Error in writing data to the NetworkSocket\n");
     158    }
     159  }
    117160
    118161
     
    124167  if( this->state == NET_REC_HEADER)
    125168  {
    126     dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));
     169//    dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));
    127170    if( dataLength == sizeof(Header))
    128171    {
     
    139182  {
    140183    /* now read the data */
    141     dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);
     184//    dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);
    142185    /* check if the data is available and process it if so */
    143186    if( dataLength == this->packetHeader.length)
    144187    {
    145       printf("NetworkStream::processData() - Got Data: \n");
     188      printf("NetworkStream::processData() - Got Data: %i bytes\n", dataLength);
    146189      /* send the received data to connectionMonitor */
    147190      this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length);
    148191      /* now pass the data to the sync object */
    149       this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length);
     192      if( !this->isServer())
     193        this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length);
    150194
    151195      this->state = NET_REC_HEADER;
Note: See TracChangeset for help on using the changeset viewer.