Changeset 5996 in orxonox.OLD for trunk/src/lib/network/network_stream.cc
- Timestamp:
- Dec 9, 2005, 12:31:01 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/network/network_stream.cc
r5822 r5996 40 40 41 41 NetworkStream::NetworkStream() 42 : DataStream()42 : DataStream() 43 43 { 44 44 this->init(); 45 45 /* initialize the references */ 46 this->type = NET_CLIENT; 46 47 this->networkSocket = new NetworkSocket(); 47 48 this->networkProtocol = new NetworkProtocol(); … … 50 51 } 51 52 53 NetworkStream::NetworkStream(IPaddress& address, NodeType type) 54 { 55 this->type = type; 56 this->init(); 57 this->networkSocket = new NetworkSocket(address); 58 this->networkProtocol = new NetworkProtocol(); 59 this->synchronizeables = NULL; 60 this->connectionMonitor = new ConnectionMonitor(); 61 } 62 63 64 NetworkStream::NetworkStream(unsigned int port, NodeType type) 65 { 66 this->type = type; 67 this->init(); 68 this->networkSocket = new NetworkSocket(); 69 // this->networkSocket->listen(port); 70 this->networkProtocol = new NetworkProtocol(); 71 this->synchronizeables = NULL; 72 this->connectionMonitor = new ConnectionMonitor(); 73 } 74 52 75 53 76 NetworkStream::NetworkStream(IPaddress& address, Synchronizeable& sync, NodeType type) 54 : DataStream() 55 { 77 : DataStream() 78 { 79 this->type = type; 56 80 this->init(); 57 81 this->networkSocket = new NetworkSocket(address); … … 59 83 this->synchronizeables = &sync; 60 84 this->connectionMonitor = new ConnectionMonitor(); 85 this->bActive = true; 61 86 } 62 87 63 88 64 89 NetworkStream::NetworkStream(unsigned int port, Synchronizeable& sync, NodeType type) 65 : DataStream() 66 { 90 : DataStream() 91 { 92 this->type = type; 67 93 this->init(); 68 94 this->networkSocket = new NetworkSocket(); 69 this->networkSocket->listen(port);95 // this->networkSocket->listen(port); 70 96 this->networkProtocol = new NetworkProtocol(); 71 97 this->synchronizeables = &sync; 72 98 this->connectionMonitor = new ConnectionMonitor(); 99 this->bActive = true; 73 100 } 74 101 … … 79 106 this->setClassID(CL_NETWORK_STREAM, "NetworkStream"); 80 107 this->state = NET_REC_HEADER; 108 this->bActive = false; 81 109 } 82 110 … … 85 113 { 86 114 87 networkSocket->disconnectServer(); 88 89 if( this->networkSocket) 90 delete networkSocket; 91 92 delete connectionMonitor; 93 delete networkProtocol; 94 } 115 networkSocket->disconnectServer(); 116 117 if( this->networkSocket) 118 delete networkSocket; 119 120 delete connectionMonitor; 121 delete networkProtocol; 122 } 123 124 125 void NetworkStream::connectSynchronizeable(Synchronizeable& sync) 126 { 127 this->synchronizeables = &sync; 128 if( this->networkSocket != NULL) 129 this->bActive = true; 130 } 131 95 132 96 133 void NetworkStream::processData() … … 102 139 PRINT(0)("============= DOWNSTREAM:===============\n"); 103 140 /* first of all read the synchronizeable's data: */ 104 dataLength = this->synchronizeables->readBytes((byte*)downBuffer); 105 106 /* send the received data to connectionMonitor */ 107 this->connectionMonitor->processPacket((byte*)downBuffer, dataLength); 108 109 dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, 110 *(this->synchronizeables), 12/* some random number (no real id)*/); 111 112 /* pass the data to the network socket */ 113 dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength); 114 /* check if there was an error */ 115 if( dataLength == -1) { PRINTF(0)("Error in writing data to the NetworkSocket\n");} 116 141 if( this->isServer()) 142 dataLength = this->synchronizeables->readBytes((byte*)downBuffer); 143 144 if( dataLength > 0) 145 { 146 /* send the received data to connectionMonitor */ 147 this->connectionMonitor->processPacket((byte*)downBuffer, dataLength); 148 149 dataLength = this->networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, 150 *(this->synchronizeables), 12/* some random number (no real id)*/); 151 152 /* pass the data to the network socket */ 153 // dataLength = this->networkSocket->writeBytes((byte*)downBuffer, dataLength); 154 /* check if there was an error */ 155 if( dataLength == -1) 156 { 157 PRINTF(0)("Error in writing data to the NetworkSocket\n"); 158 } 159 } 117 160 118 161 … … 124 167 if( this->state == NET_REC_HEADER) 125 168 { 126 dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header));169 // dataLength = this->networkSocket->readBlock((byte*)upBuffer, sizeof(Header)); 127 170 if( dataLength == sizeof(Header)) 128 171 { … … 139 182 { 140 183 /* now read the data */ 141 dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length);184 // dataLength = this->networkSocket->readBlock((byte*)upBuffer, this->packetHeader.length); 142 185 /* check if the data is available and process it if so */ 143 186 if( dataLength == this->packetHeader.length) 144 187 { 145 printf("NetworkStream::processData() - Got Data: \n");188 printf("NetworkStream::processData() - Got Data: %i bytes\n", dataLength); 146 189 /* send the received data to connectionMonitor */ 147 190 this->connectionMonitor->processPacket((byte*)upBuffer, this->packetHeader.length); 148 191 /* now pass the data to the sync object */ 149 this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length); 192 if( !this->isServer()) 193 this->synchronizeables->writeBytes((byte*)upBuffer, this->packetHeader.length); 150 194 151 195 this->state = NET_REC_HEADER;
Note: See TracChangeset
for help on using the changeset viewer.