Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2005, 3:45:57 PM (19 years ago)
Author:
rennerc
Message:

network_stream: added possibility to connect to >1 hosts

File:
1 edited

Legend:

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

    r5996 r6007  
    4545  /* initialize the references */
    4646  this->type = NET_CLIENT;
    47   this->networkSocket = new NetworkSocket();
    4847  this->networkProtocol = new NetworkProtocol();
    49   this->synchronizeables = NULL;
    5048  this->connectionMonitor = new ConnectionMonitor();
    5149}
    5250
    53 NetworkStream::NetworkStream(IPaddress& address, NodeType type)
     51NetworkStream::NetworkStream(IPaddress& address)
    5452{
    55   this->type = type;
     53  this->type = NET_CLIENT;
    5654  this->init();
    57   this->networkSocket = new NetworkSocket(address);
     55  this->networkSockets.push_back(new NetworkSocket(address));
    5856  this->networkProtocol = new NetworkProtocol();
    59   this->synchronizeables = NULL;
    6057  this->connectionMonitor = new ConnectionMonitor();
    6158}
    6259
    6360
    64 NetworkStream::NetworkStream(unsigned int port, NodeType type)
     61NetworkStream::NetworkStream(unsigned int port)
    6562{
    66   this->type = type;
     63  this->type = NET_SERVER;
    6764  this->init();
    68   this->networkSocket = new NetworkSocket();
    69 //  this->networkSocket->listen(port);
     65  this->serverSocket = new ServerSocket(port);
    7066  this->networkProtocol = new NetworkProtocol();
    71   this->synchronizeables = NULL;
    7267  this->connectionMonitor = new ConnectionMonitor();
    73 }
    74 
    75 
    76 NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type)
    77     : DataStream()
    78 {
    79   this->type = type;
    80   this->init();
    81   this->networkSocket = new NetworkSocket(address);
    82   this->networkProtocol = new NetworkProtocol();
    83   this->synchronizeables = &sync;
    84   this->connectionMonitor = new ConnectionMonitor();
    85   this->bActive = true;
    86 }
    87 
    88 
    89 NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type)
    90     : DataStream()
    91 {
    92   this->type = type;
    93   this->init();
    94   this->networkSocket = new NetworkSocket();
    95 //  this->networkSocket->listen(port);
    96   this->networkProtocol = new NetworkProtocol();
    97   this->synchronizeables = &sync;
    98   this->connectionMonitor = new ConnectionMonitor();
    99   this->bActive = true;
    10068}
    10169
     
    10573  /* set the class id for the base object */
    10674  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
    107   this->state = NET_REC_HEADER;
    10875  this->bActive = false;
     76  this->serverSocket = NULL;
    10977}
    11078
     
    11280NetworkStream::~NetworkStream()
    11381{
     82  if ( this->serverSocket )
     83  {
     84    serverSocket->close();
     85    delete serverSocket;
     86  }
    11487
    115   networkSocket->disconnectServer();
    116 
    117   if( this->networkSocket)
    118     delete networkSocket;
     88  for (NetworkSocketVector::iterator i = networkSockets.begin(); i!=networkSockets.end(); i++)
     89  {
     90    if ( *i )
     91    {
     92      (*i)->disconnectServer();
     93      delete *i;
     94    }
     95  }
    11996
    12097  delete connectionMonitor;
     
    125102void NetworkStream::connectSynchronizeable(Synchronizeable& sync)
    126103{
    127   this->synchronizeables = &sync;
    128   if( this->networkSocket != NULL)
     104  this->synchronizeables.push_back(&sync);
     105
     106  if( this->networkSockets.size()>0 )
    129107    this->bActive = true;
    130108}
     
    133111void NetworkStream::processData()
    134112{
     113#if 0
    135114  int dataLength = 0;
    136115
     
    197176  }
    198177
    199 
     178#endif
    200179}
Note: See TracChangeset for help on using the changeset viewer.