MCPcopy Create free account
hub / github.com/SFML/SFML / doServer

Function doServer

examples/voip/Server.cpp:177–205  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// Launch a server and wait for incoming audio data from a connected client ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

175///
176////////////////////////////////////////////////////////////
177void 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}

Callers 1

mainFunction · 0.85

Calls 4

sleepFunction · 0.85
startMethod · 0.45
getStatusMethod · 0.45
playMethod · 0.45

Tested by

no test coverage detected