Changeset 5804 in orxonox.OLD for branches/network
- Timestamp:
- Nov 28, 2005, 5:49:48 PM (19 years ago)
- Location:
- branches/network/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/defs/debug.h
r5619 r5804 62 62 #define DEBUG_MODULE_ORXONOX 2 63 63 #define DEBUG_MODULE_WORLD 2 64 #define DEBUG_MODULE_NETWORK 264 #define DEBUG_MODULE_NETWORK 4 65 65 66 66 // LOADING -
branches/network/src/lib/network/network_manager.cc
r5798 r5804 76 76 /* set the class id for the base object */ 77 77 this->setClassID(CL_NETWORK_MANAGER, "NetworkManager"); 78 78 79 79 /* initialize the references */ 80 80 this->netStreamList = NULL; 81 81 this->syncList = NULL; 82 82 83 83 PRINTF(0)("NetworkManager created\n"); 84 84 } … … 128 128 NetworkStream& NetworkManager::establishConnection(IPaddress& address, Synchronizeable& sync) 129 129 { 130 PRINTF(0)("Establish connection...\n");130 printf("Establish connection to server %s, on port %u\n", SDLNet_ResolveIP(&address), address.port); 131 131 /* creating a new network stream, it will register itself automaticaly to the class list */ 132 132 NetworkStream* netStream = new NetworkStream(address, sync, NET_CLIENT); … … 137 137 * @param sync: the listener 138 138 */ 139 NetworkStream& NetworkManager::createServer(Synchronizeable& sync, int port)139 NetworkStream& NetworkManager::createServer(Synchronizeable& sync, unsigned int port) 140 140 { 141 PRINTF(0)("Create a new server socket...\n");141 printf("Create a new server socket, liestening on port %u...\n", port); 142 142 /* creating a new network stream, it will register itself automaticaly to the class list */ 143 143 NetworkStream* netStream = new NetworkStream(sync, port, NET_SERVER); … … 160 160 void NetworkManager::synchronize() 161 161 { 162 PRINTF(0)("NetworkManager synchronizes\n");163 162 if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL) 164 163 { … … 167 166 while( stream) 168 167 { 169 printf("NetworkManager::synchronize ");170 if(stream->isServer()) printf("Server\n"); else printf("Client\n");171 168 stream->processData(); 172 169 stream = (NetworkStream*)(iterator->nextElement()); -
branches/network/src/lib/network/network_manager.h
r5649 r5804 32 32 void initialize(); 33 33 void shutdown(); 34 34 35 35 NetworkStream& establishConnection(IPaddress& address, Synchronizeable& sync); 36 36 NetworkStream& establishConnection(const char& hostName, const Synchronizeable& sync); 37 NetworkStream& createServer(Synchronizeable& sync, int port);37 NetworkStream& createServer(Synchronizeable& sync, unsigned int port); 38 38 void shutdownConnection(); 39 39 40 40 void synchronize(); 41 41 … … 43 43 tList<BaseObject>* netStreamList; // list with refs to all network streams 44 44 tList<BaseObject>* syncList; // list of synchronizeables 45 45 46 46 }; 47 47 -
branches/network/src/lib/network/network_socket.cc
r5798 r5804 63 63 * Constructor to connect directly 64 64 */ 65 NetworkSocket::NetworkSocket(IPaddress ip , unsigned int port)65 NetworkSocket::NetworkSocket(IPaddress ip) 66 66 { 67 67 NetworkSocket(); 68 connectToServer(ip , port);68 connectToServer(ip); 69 69 } 70 70 … … 90 90 * It is called by the NetworkStream. It creates a TCP/UDP socket for the connection. 91 91 * @param ip 92 * @param port 93 */ 94 void NetworkSocket::connectToServer(IPaddress ip, unsigned int port) 92 */ 93 void NetworkSocket::connectToServer(IPaddress ip) 95 94 { 96 95 //check if not already connected or listening … … 218 217 memcpy(outgoingBuffer + outgoingBufferLength, data, nbytes); 219 218 outgoingBufferLength += nbytes; 220 219 221 220 SDL_mutexV(outgoingBufferMutex); 222 221 … … 287 286 int NetworkSocket::readBlock(byte * data, int length) 288 287 { 288 printf("NetworkSocket: got %i bytes, NetworkStream requested %i bytes\n", this->incomingBufferLength, length); 289 289 if (incomingBufferLength >= length) 290 290 return readBytes(data, length); -
branches/network/src/lib/network/network_socket.h
r5733 r5804 73 73 74 74 NetworkSocket(); 75 NetworkSocket(IPaddress ip , unsigned int port);75 NetworkSocket(IPaddress ip); 76 76 ~NetworkSocket(); 77 77 78 void connectToServer(IPaddress ip , unsigned int port);78 void connectToServer(IPaddress ip); 79 79 void listen(unsigned int port); 80 80 void disconnectServer(); -
branches/network/src/lib/network/network_stream.cc
r5802 r5804 55 55 { 56 56 this->init(); 57 this->networkSocket = new NetworkSocket( address, 9999 ); 58 // this->networkSocket->connectToServer(address, 88); 57 this->networkSocket = new NetworkSocket(address); 59 58 this->networkProtocol = new NetworkProtocol(); 60 59 this->synchronizeables = &sync; … … 63 62 64 63 65 NetworkStream::NetworkStream(Synchronizeable& sync, int port, NodeType type)64 NetworkStream::NetworkStream(Synchronizeable& sync, unsigned int port, NodeType type) 66 65 : DataStream() 67 66 { 68 67 this->init(); 69 this->networkSocket = new NetworkSocket( /* address, type */);70 this->networkSocket->listen( 9999);68 this->networkSocket = new NetworkSocket(); 69 this->networkSocket->listen(port); 71 70 this->networkProtocol = new NetworkProtocol(); 72 71 this->synchronizeables = &sync; … … 94 93 void NetworkStream::processData() 95 94 { 96 97 98 95 int ret = 0; 99 96 100 97 /* DOWNSTREAM */ 101 102 PRINT(0)("\n\n"); 98 printf("\nSynchronizeable: %s\n", this->synchronizeables->getName()); 103 99 PRINT(0)("============= DOWNSTREAM:===============\n"); 104 100 /* first of all read the synchronizeable's data: */ … … 121 117 122 118 /* UPSTREAM */ 123 124 119 ret = 0; 125 120 PRINT(0)("============== UPSTREAM:================\n"); … … 128 123 /* error checking: data read? */ 129 124 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");} 131 126 else 132 127 { … … 135 130 136 131 /* extract Header */ 137 this->networkProtocol->extractHeader((byte*) upBuffer , ret);132 Header header = this->networkProtocol->extractHeader((byte*) upBuffer , ret); 138 133 139 134 /* now pass the data to the sync object */ 140 this->synchronizeables->writeBytes((byte*)upBuffer, ret);135 this->synchronizeables->writeBytes((byte*)upBuffer, header.length); 141 136 } 142 137 -
branches/network/src/lib/network/network_stream.h
r5798 r5804 20 20 NetworkStream(); 21 21 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 24 24 ~NetworkStream(); 25 25 26 26 void init(); 27 27 28 28 inline bool isServer() { return (this->type == NET_SERVER)? true:false; } 29 29 virtual void processData(); … … 31 31 private: 32 32 NetworkProtocol* networkProtocol; 33 //NetworkSocket* 33 //NetworkSocket* networkSockets; 34 34 ConnectionMonitor* connectionMonitor; 35 35 // tList<Synchronizeable>* synchronizeables; 36 Synchronizeable* 36 Synchronizeable* synchronizeables; 37 37 NetworkSocket* networkSocket; 38 38 int type; -
branches/network/src/lib/network/synchronizeable.cc
r5650 r5804 21 21 \brief default constructor 22 22 */ 23 Synchronizeable::Synchronizeable( )23 Synchronizeable::Synchronizeable(const char* name) 24 24 { 25 26 25 this->name = name; 27 26 } 28 27 -
branches/network/src/lib/network/synchronizeable.h
r5650 r5804 11 11 12 12 class Synchronizeable : virtual public BaseObject 13 {14 13 { 14 public: 15 15 16 Synchronizeable();17 16 Synchronizeable(const char* name); 17 ~Synchronizeable(); 18 18 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(); 23 23 24 inline const char* getName() { return this->name; } 24 25 25 26 private: 26 27 27 int uniqueID; 28 int uniqueID; 29 const char* name; 28 30 29 }; 30 31 }; 31 32 #endif /* _SYNCHRONIZEABLE_H */ -
branches/network/src/subprojects/network/network_unit_test.cc
r5800 r5804 36 36 SDL_Delay(20); 37 37 38 NetworkSocket client(ip , 9999);38 NetworkSocket client(ip); 39 39 40 40 char buf[1024]; … … 123 123 printf("=================\n"); 124 124 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"); 130 127 131 128 unsigned int port = 9999; 132 129 133 130 /* create the network manager */ … … 138 135 139 136 /* create a server stream */ 140 nm->createServer(*serverSync, 9999);137 nm->createServer(*serverSync, port); 141 138 142 139 /* 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"); 143 144 nm->establishConnection(ip, *clientSync); 144 145 -
branches/network/src/subprojects/network/simple_sync.cc
r5802 r5804 28 28 * default constructor 29 29 */ 30 SimpleSync::SimpleSync( )31 : Synchronizeable( )30 SimpleSync::SimpleSync(const char* name) 31 : Synchronizeable(name) 32 32 { 33 33 this->outLength = 10; -
branches/network/src/subprojects/network/simple_sync.h
r5800 r5804 13 13 { 14 14 public: 15 SimpleSync( );15 SimpleSync(const char* name); 16 16 ~SimpleSync(); 17 17 18 18 virtual void writeBytes(byte* data, int length); 19 19 virtual int readBytes(byte* data); 20 20 21 21 22 private:
Note: See TracChangeset
for help on using the changeset viewer.