Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5804 in orxonox.OLD for branches/network


Ignore:
Timestamp:
Nov 28, 2005, 5:49:48 PM (19 years ago)
Author:
patrick
Message:

network: changed the synchronizeable interface, since the data synchronizeables, more debug output

Location:
branches/network/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/defs/debug.h

    r5619 r5804  
    6262  #define DEBUG_MODULE_ORXONOX               2
    6363  #define DEBUG_MODULE_WORLD                 2
    64   #define DEBUG_MODULE_NETWORK               2
     64  #define DEBUG_MODULE_NETWORK               4
    6565
    6666  // LOADING
  • branches/network/src/lib/network/network_manager.cc

    r5798 r5804  
    7676  /* set the class id for the base object */
    7777  this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
    78  
     78
    7979  /* initialize the references */
    8080  this->netStreamList = NULL;
    8181  this->syncList = NULL;
    82  
     82
    8383  PRINTF(0)("NetworkManager created\n");
    8484}
     
    128128NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync)
    129129{
    130   PRINTF(0)("Establish connection...\n");
     130  printf("Establish connection to server %s, on port %u\n", SDLNet_ResolveIP(&address), address.port);
    131131  /* creating a new network stream, it will register itself automaticaly to the class list */
    132132  NetworkStream* netStream = new NetworkStream(address, sync, NET_CLIENT);
     
    137137 * @param sync: the listener
    138138 */
    139 NetworkStream& NetworkManager::createServer(Synchronizeable& sync, int port)
     139NetworkStream& NetworkManager::createServer(Synchronizeable& sync, unsigned int port)
    140140{
    141   PRINTF(0)("Create a new server socket...\n");
     141  printf("Create a new server socket, liestening on port %u...\n", port);
    142142  /* creating a new network stream, it will register itself automaticaly to the class list */
    143143  NetworkStream* netStream = new NetworkStream(sync, port, NET_SERVER);
     
    160160void NetworkManager::synchronize()
    161161{
    162   PRINTF(0)("NetworkManager synchronizes\n");
    163162  if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL)
    164163  {
     
    167166    while( stream)
    168167    {
    169       printf("NetworkManager::synchronize ");
    170       if(stream->isServer()) printf("Server\n"); else printf("Client\n");
    171168      stream->processData();
    172169      stream = (NetworkStream*)(iterator->nextElement());
  • branches/network/src/lib/network/network_manager.h

    r5649 r5804  
    3232  void initialize();
    3333  void shutdown();
    34  
     34
    3535  NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync);
    3636  NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync);
    37   NetworkStream& createServer(Synchronizeable& sync, int port);
     37  NetworkStream& createServer(Synchronizeable& sync, unsigned int port);
    3838  void shutdownConnection();
    39  
     39
    4040  void synchronize();
    4141
     
    4343  tList<BaseObject>*    netStreamList;            // list with refs to all network streams
    4444  tList<BaseObject>*  syncList;                 // list of synchronizeables
    45    
     45
    4646};
    4747
  • branches/network/src/lib/network/network_socket.cc

    r5798 r5804  
    6363 * Constructor to connect directly
    6464 */
    65 NetworkSocket::NetworkSocket(IPaddress ip, unsigned int port)
     65NetworkSocket::NetworkSocket(IPaddress ip)
    6666{
    6767  NetworkSocket();
    68   connectToServer(ip, port);
     68  connectToServer(ip);
    6969}
    7070
     
    9090 * It is called by the NetworkStream. It creates a TCP/UDP socket for the connection.
    9191 * @param ip
    92  * @param port
    93  */
    94 void NetworkSocket::connectToServer(IPaddress ip, unsigned int port)
     92 */
     93void NetworkSocket::connectToServer(IPaddress ip)
    9594{
    9695  //check if not already connected or listening
     
    218217  memcpy(outgoingBuffer + outgoingBufferLength, data, nbytes);
    219218  outgoingBufferLength += nbytes;
    220  
     219
    221220  SDL_mutexV(outgoingBufferMutex);
    222221
     
    287286int NetworkSocket::readBlock(byte * data, int length)
    288287{
     288  printf("NetworkSocket: got %i bytes, NetworkStream requested %i bytes\n", this->incomingBufferLength, length);
    289289  if (incomingBufferLength >= length)
    290290    return readBytes(data, length);
  • branches/network/src/lib/network/network_socket.h

    r5733 r5804  
    7373
    7474  NetworkSocket();
    75   NetworkSocket(IPaddress ip, unsigned int port);
     75  NetworkSocket(IPaddress ip);
    7676  ~NetworkSocket();
    7777
    78   void connectToServer(IPaddress ip, unsigned int port);
     78  void connectToServer(IPaddress ip);
    7979  void listen(unsigned int port);
    8080  void disconnectServer();
  • branches/network/src/lib/network/network_stream.cc

    r5802 r5804  
    5555{
    5656  this->init();
    57   this->networkSocket = new NetworkSocket( address, 9999 );
    58    // this->networkSocket->connectToServer(address, 88);
     57  this->networkSocket = new NetworkSocket(address);
    5958  this->networkProtocol = new NetworkProtocol();
    6059  this->synchronizeables = &sync;
     
    6362
    6463
    65 NetworkStream::NetworkStream(Synchronizeable& sync, int port, NodeType type)
     64NetworkStream::NetworkStream(Synchronizeable& sync, unsigned int port, NodeType type)
    6665  : DataStream()
    6766{
    6867  this->init();
    69   this->networkSocket = new NetworkSocket(/* address, type */);
    70   this->networkSocket->listen(9999);
     68  this->networkSocket = new NetworkSocket();
     69  this->networkSocket->listen(port);
    7170  this->networkProtocol = new NetworkProtocol();
    7271  this->synchronizeables = &sync;
     
    9493void NetworkStream::processData()
    9594{
    96 
    97 
    9895  int ret = 0;
    9996
    10097  /* DOWNSTREAM */
    101 
    102   PRINT(0)("\n\n");
     98  printf("\nSynchronizeable: %s\n", this->synchronizeables->getName());
    10399  PRINT(0)("============= DOWNSTREAM:===============\n");
    104100  /* first of all read the synchronizeable's data: */
     
    121117
    122118  /* UPSTREAM */
    123 
    124119  ret = 0;
    125120  PRINT(0)("============== UPSTREAM:================\n");
     
    128123  /* error checking: data read? */
    129124  printf("NetworkSocket: received %i bytes\n", ret);
    130   if( ret != PACKAGE_SIZE + sizeof(Header)) { PRINTF(0)("Error while reading data from the NetworkSocket. Skipping further work\n");}
     125  if( ret != 11 /*PACKAGE_SIZE + sizeof(Header)*/) { PRINTF(0)("Error while reading data from the NetworkSocket. Skipping further work\n");}
    131126  else
    132127  {
     
    135130
    136131    /* extract Header */
    137     this->networkProtocol->extractHeader((byte*) upBuffer , ret);
     132    Header header = this->networkProtocol->extractHeader((byte*) upBuffer , ret);
    138133
    139134    /* now pass the data to the sync object */
    140     this->synchronizeables->writeBytes((byte*)upBuffer, ret);
     135    this->synchronizeables->writeBytes((byte*)upBuffer, header.length);
    141136  }
    142137
  • branches/network/src/lib/network/network_stream.h

    r5798 r5804  
    2020  NetworkStream();
    2121  NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);
    22   NetworkStream(Synchronizeable& sync, int port, NodeType type);
    23  
     22  NetworkStream(Synchronizeable& sync, unsigned int port, NodeType type);
     23
    2424  ~NetworkStream();
    25    
     25
    2626  void init();
    27  
     27
    2828  inline bool isServer() { return (this->type == NET_SERVER)? true:false; }
    2929  virtual void processData();
     
    3131private:
    3232   NetworkProtocol* networkProtocol;
    33    //NetworkSocket*       networkSockets;
     33   //NetworkSocket*       networkSockets;
    3434   ConnectionMonitor*      connectionMonitor;
    3535   // tList<Synchronizeable>* synchronizeables;
    36    Synchronizeable*         synchronizeables;
     36   Synchronizeable*         synchronizeables;
    3737   NetworkSocket* networkSocket;
    3838   int                    type;
  • branches/network/src/lib/network/synchronizeable.cc

    r5650 r5804  
    2121                   \brief default constructor
    2222 */
    23 Synchronizeable::Synchronizeable()
     23Synchronizeable::Synchronizeable(const char* name)
    2424{
    25 
    26 
     25  this->name = name;
    2726}
    2827
  • branches/network/src/lib/network/synchronizeable.h

    r5650 r5804  
    1111
    1212class Synchronizeable : virtual public BaseObject
    13 {
    14         public:
     13  {
     14  public:
    1515
    16                    Synchronizeable();
    17                    ~Synchronizeable();
     16    Synchronizeable(const char* name);
     17    ~Synchronizeable();
    1818
    19  virtual void      writeBytes(byte* data, int length);
    20  virtual int       readBytes(byte* data);
    21  virtual void      writeDebug();
    22  virtual void      readDebug();
     19    virtual void      writeBytes(byte* data, int length);
     20    virtual int       readBytes(byte* data);
     21    virtual void      writeDebug();
     22    virtual void      readDebug();
    2323
     24    inline const char* getName() { return this->name; }
    2425
    25         private:
     26  private:
    2627
    27  int               uniqueID;
     28    int               uniqueID;
     29    const char*       name;
    2830
    29 };
    30 
     31  };
    3132#endif /* _SYNCHRONIZEABLE_H */
  • branches/network/src/subprojects/network/network_unit_test.cc

    r5800 r5804  
    3636  SDL_Delay(20);
    3737
    38   NetworkSocket client(ip, 9999);
     38  NetworkSocket client(ip);
    3939
    4040  char buf[1024];
     
    123123  printf("=================\n");
    124124
    125   IPaddress ip;
    126   //SDLNet_ResolveHost(&ip, "127.0.0.1", 9999);
    127   SDLNet_ResolveHost(&ip, "localhost", 9999);
    128   Synchronizeable* clientSync = new SimpleSync();
    129   Synchronizeable* serverSync = new SimpleSync();
     125  Synchronizeable* clientSync = new SimpleSync("Client\0");
     126  Synchronizeable* serverSync = new SimpleSync("Server\0");
    130127
    131 
     128  unsigned int port = 9999;
    132129
    133130  /* create the network manager */
     
    138135
    139136  /* create a server stream */
    140   nm->createServer(*serverSync, 9999);
     137  nm->createServer(*serverSync, port);
    141138
    142139  /* esatblish a connection */
     140  IPaddress ip;
     141  int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port);
     142  //SDLNet_ResolveHost(&ip, "localhost", port);
     143  if(error == -1) printf("\n\nerror on address resolution, program inconsistancy\n\n");
    143144  nm->establishConnection(ip, *clientSync);
    144145
  • branches/network/src/subprojects/network/simple_sync.cc

    r5802 r5804  
    2828 *  default constructor
    2929 */
    30 SimpleSync::SimpleSync()
    31   : Synchronizeable()
     30SimpleSync::SimpleSync(const char* name)
     31  : Synchronizeable(name)
    3232{
    3333  this->outLength = 10;
  • branches/network/src/subprojects/network/simple_sync.h

    r5800 r5804  
    1313{
    1414  public:
    15     SimpleSync();
     15    SimpleSync(const char* name);
    1616    ~SimpleSync();
    1717
    1818    virtual void writeBytes(byte* data, int length);
    1919    virtual int readBytes(byte* data);
     20
    2021
    2122  private:
Note: See TracChangeset for help on using the changeset viewer.