Changeset 6007 in orxonox.OLD for branches/network
- Timestamp:
- Dec 10, 2005, 3:45:57 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_manager.cc
r5997 r6007 95 95 } 96 96 97 this->tmpStream = new NetworkStream(ipAddress , NET_CLIENT);97 this->tmpStream = new NetworkStream(ipAddress); 98 98 return 1; 99 99 } … … 106 106 int NetworkManager::createServer(unsigned int port) 107 107 { 108 this->tmpStream = new NetworkStream(port , NET_SERVER);108 this->tmpStream = new NetworkStream(port); 109 109 SDL_Delay(20); 110 110 return 1; … … 120 120 { 121 121 /* 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); 123 124 } 124 125 … … 132 133 PRINTF(0)("Create a new server socket\n"); 133 134 /* 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); 135 137 } 136 138 -
branches/network/src/lib/network/network_stream.cc
r5996 r6007 45 45 /* initialize the references */ 46 46 this->type = NET_CLIENT; 47 this->networkSocket = new NetworkSocket();48 47 this->networkProtocol = new NetworkProtocol(); 49 this->synchronizeables = NULL;50 48 this->connectionMonitor = new ConnectionMonitor(); 51 49 } 52 50 53 NetworkStream::NetworkStream(IPaddress& address , NodeType type)51 NetworkStream::NetworkStream(IPaddress& address) 54 52 { 55 this->type = type;53 this->type = NET_CLIENT; 56 54 this->init(); 57 this->networkSocket = new NetworkSocket(address);55 this->networkSockets.push_back(new NetworkSocket(address)); 58 56 this->networkProtocol = new NetworkProtocol(); 59 this->synchronizeables = NULL;60 57 this->connectionMonitor = new ConnectionMonitor(); 61 58 } 62 59 63 60 64 NetworkStream::NetworkStream(unsigned int port , NodeType type)61 NetworkStream::NetworkStream(unsigned int port) 65 62 { 66 this->type = type;63 this->type = NET_SERVER; 67 64 this->init(); 68 this->networkSocket = new NetworkSocket(); 69 // this->networkSocket->listen(port); 65 this->serverSocket = new ServerSocket(port); 70 66 this->networkProtocol = new NetworkProtocol(); 71 this->synchronizeables = NULL;72 67 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;100 68 } 101 69 … … 105 73 /* set the class id for the base object */ 106 74 this->setClassID(CL_NETWORK_STREAM, "NetworkStream"); 107 this->state = NET_REC_HEADER;108 75 this->bActive = false; 76 this->serverSocket = NULL; 109 77 } 110 78 … … 112 80 NetworkStream::~NetworkStream() 113 81 { 82 if ( this->serverSocket ) 83 { 84 serverSocket->close(); 85 delete serverSocket; 86 } 114 87 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 } 119 96 120 97 delete connectionMonitor; … … 125 102 void NetworkStream::connectSynchronizeable(Synchronizeable& sync) 126 103 { 127 this->synchronizeables = &sync; 128 if( this->networkSocket != NULL) 104 this->synchronizeables.push_back(&sync); 105 106 if( this->networkSockets.size()>0 ) 129 107 this->bActive = true; 130 108 } … … 133 111 void NetworkStream::processData() 134 112 { 113 #if 0 135 114 int dataLength = 0; 136 115 … … 197 176 } 198 177 199 178 #endif 200 179 } -
branches/network/src/lib/network/network_stream.h
r5996 r6007 7 7 #define _NETWORK_STREAM 8 8 9 #include <vector> 10 #include <list> 11 9 12 #include "data_stream.h" 10 13 #include "network_protocol.h" 14 #include "server_socket.h" 11 15 12 16 class Synchronizeable; 13 17 class NetworkSocket; 18 class ServerSocket; 14 19 class ConnectionMonitor; 15 20 class NetworkProtocol; 16 21 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 }; 22 typedef std::list<Synchronizeable*> SynchronizeableList; 23 typedef std::vector<NetworkSocket*> NetworkSocketVector; 25 24 26 25 … … 30 29 public: 31 30 NetworkStream(); 32 NetworkStream(IPaddress& address , NodeType type);33 NetworkStream(unsigned int port , NodeType type);31 NetworkStream(IPaddress& address); 32 NetworkStream(unsigned int port); 34 33 35 NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type);36 NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type);37 34 ~NetworkStream(); 38 35 void init(); … … 48 45 NetworkProtocol* networkProtocol; 49 46 ConnectionMonitor* connectionMonitor; 50 Synchronizeable* synchronizeables; 51 NetworkSocket* networkSocket; 47 SynchronizeableList synchronizeables; 48 NetworkSocketVector networkSockets; 49 ServerSocket* serverSocket; 52 50 int type; 53 int state;54 51 Header packetHeader; 55 52 bool bActive; -
branches/network/src/lib/network/server_socket.cc
r5996 r6007 112 112 NetworkSocket ServerSocket::getNewSocket( ) 113 113 { 114 if ( !listenSocket ) 115 { 116 PRINTF(1)("listenSocket == NULL! Maybe you forgot to call listen()\n"); 117 close(); 118 return NULL; 119 } 120 114 121 TCPsocket sock = SDLNet_TCP_Accept(listenSocket); 115 122 … … 124 131 } 125 132 133 void 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 40 40 bool listen( unsigned int port ); 41 41 NetworkSocket getNewSocket( void ); 42 void close(); 42 43 }; 43 44
Note: See TracChangeset
for help on using the changeset viewer.