Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6007 in orxonox.OLD for branches/network


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

network_stream: added possibility to connect to >1 hosts

Location:
branches/network/src/lib/network
Files:
5 edited

Legend:

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

    r5997 r6007  
    9595  }
    9696
    97   this->tmpStream = new NetworkStream(ipAddress, NET_CLIENT);
     97  this->tmpStream = new NetworkStream(ipAddress);
    9898  return 1;
    9999}
     
    106106int NetworkManager::createServer(unsigned int port)
    107107{
    108   this->tmpStream = new NetworkStream(port, NET_SERVER);
     108  this->tmpStream = new NetworkStream(port);
    109109  SDL_Delay(20);
    110110  return 1;
     
    120120{
    121121  /* creating a new network stream, it will register itself automaticaly to the class list */
    122   this->tmpStream = new NetworkStream(address, sync, NET_CLIENT);
     122  this->tmpStream = new NetworkStream(address);
     123  this->tmpStream->connectSynchronizeable(sync);
    123124}
    124125
     
    132133  PRINTF(0)("Create a new server socket\n");
    133134  /* creating a new network stream, it will register itself automaticaly to the class list */
    134   this->tmpStream = new NetworkStream(port, sync, NET_SERVER);
     135  this->tmpStream = new NetworkStream(port);
     136  this->tmpStream->connectSynchronizeable(sync);
    135137}
    136138
  • 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}
  • branches/network/src/lib/network/network_stream.h

    r5996 r6007  
    77#define _NETWORK_STREAM
    88
     9#include <vector>
     10#include <list>
     11
    912#include "data_stream.h"
    1013#include "network_protocol.h"
     14#include "server_socket.h"
    1115
    1216class Synchronizeable;
    1317class NetworkSocket;
     18class ServerSocket;
    1419class ConnectionMonitor;
    1520class NetworkProtocol;
    1621
    17 
    18 //<! The state of the NetworkStream
    19 typedef enum NetStat {
    20   NET_REC_HEADER = 0,                          //!< Waiting for header
    21   NET_REC_DATA,                                //!< Waiting for data
    22 
    23   NUM_STATES                                   //!< Number of states
    24 };
     22typedef std::list<Synchronizeable*>  SynchronizeableList;
     23typedef std::vector<NetworkSocket*> NetworkSocketVector;
    2524
    2625
     
    3029  public:
    3130    NetworkStream();
    32     NetworkStream(IPaddress& address, NodeType type);
    33     NetworkStream(unsigned int port, NodeType type);
     31    NetworkStream(IPaddress& address);
     32    NetworkStream(unsigned int port);
    3433
    35     NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);
    36     NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type);
    3734    ~NetworkStream();
    3835    void init();
     
    4845    NetworkProtocol*       networkProtocol;
    4946    ConnectionMonitor*     connectionMonitor;
    50     Synchronizeable*       synchronizeables;
    51     NetworkSocket*         networkSocket;
     47    SynchronizeableList    synchronizeables;
     48    NetworkSocketVector    networkSockets;
     49    ServerSocket*          serverSocket;
    5250    int                    type;
    53     int                    state;
    5451    Header                 packetHeader;
    5552    bool                   bActive;
  • branches/network/src/lib/network/server_socket.cc

    r5996 r6007  
    112112NetworkSocket ServerSocket::getNewSocket( )
    113113{
     114  if ( !listenSocket )
     115  {
     116    PRINTF(1)("listenSocket == NULL! Maybe you forgot to call listen()\n");
     117    close();
     118    return NULL;
     119  }
     120
    114121  TCPsocket sock = SDLNet_TCP_Accept(listenSocket);
    115122
     
    124131}
    125132
     133void ServerSocket::close( )
     134{
     135  if ( listenSocket )
     136  {
     137    SDLNet_TCP_Close( listenSocket );
     138    listenSocket = NULL;
     139  }
     140
     141  _isListening = false;
     142}
     143
  • branches/network/src/lib/network/server_socket.h

    r5996 r6007  
    4040    bool listen( unsigned int port );
    4141    NetworkSocket getNewSocket( void );
     42    void close();
    4243};
    4344
Note: See TracChangeset for help on using the changeset viewer.