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

Function doClient

examples/voip/Client.cpp:115–153  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// Create a client, connect it to a running server and start sending it audio data ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

113///
114////////////////////////////////////////////////////////////
115void doClient(unsigned short port)
116{
117 // Check that the device can capture audio
118 if (!sf::SoundRecorder::isAvailable())
119 {
120 std::cout << "Sorry, audio capture is not supported by your system" << std::endl;
121 return;
122 }
123
124 // Ask for server address
125 std::optional<sf::IpAddress> server;
126 do
127 {
128 std::cout << "Type address or name of the server to connect to: ";
129 std::string hostname;
130 std::cin >> hostname;
131 if (const auto addresses = sf::Dns::resolve(hostname); addresses.has_value() && !addresses->empty())
132 server = addresses->front();
133 } while (!server.has_value());
134
135 // Create an instance of our custom recorder
136 NetworkRecorder recorder(server.value(), port);
137
138 // Wait for user input...
139 std::cin.ignore(10'000, '\n');
140 std::cout << "Press enter to start recording audio";
141 std::cin.ignore(10'000, '\n');
142
143 // Start capturing audio data
144 if (!recorder.start(44100))
145 {
146 std::cerr << "Failed to start recorder" << std::endl;
147 return;
148 }
149
150 std::cout << "Recording... press enter to stop";
151 std::cin.ignore(10'000, '\n');
152 recorder.stop();
153}

Callers 1

mainFunction · 0.85

Calls 3

isAvailableFunction · 0.50
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected