/////////////////////////////////////////////////////// Launch a server and wait for incoming audio data from a connected client ///////////////////////////////////////////////////////
| 175 | /// |
| 176 | //////////////////////////////////////////////////////////// |
| 177 | void doServer(unsigned short port) |
| 178 | { |
| 179 | // Build an audio stream to play sound data as it is received through the network |
| 180 | NetworkAudioStream audioStream; |
| 181 | audioStream.start(port); |
| 182 | |
| 183 | // Loop until the sound playback is finished |
| 184 | while (audioStream.getStatus() != sf::SoundStream::Status::Stopped) |
| 185 | { |
| 186 | // Leave some CPU time for other threads |
| 187 | sf::sleep(sf::milliseconds(100)); |
| 188 | } |
| 189 | |
| 190 | std::cin.ignore(10'000, '\n'); |
| 191 | |
| 192 | // Wait until the user presses 'enter' key |
| 193 | std::cout << "Press enter to replay the sound..." << std::endl; |
| 194 | std::cin.ignore(10'000, '\n'); |
| 195 | |
| 196 | // Replay the sound (just to make sure replaying the received data is OK) |
| 197 | audioStream.play(); |
| 198 | |
| 199 | // Loop until the sound playback is finished |
| 200 | while (audioStream.getStatus() != sf::SoundStream::Status::Stopped) |
| 201 | { |
| 202 | // Leave some CPU time for other threads |
| 203 | sf::sleep(sf::milliseconds(100)); |
| 204 | } |
| 205 | } |