Back to index

libsfml  1.6+dfsg2
Classes | Functions | Variables
Client.cpp File Reference
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>
#include <iostream>

Go to the source code of this file.


class  NetworkRecorder
 Specialization of audio recorder for sending recorded audio data through the network /////////////////////////////////////////////////////////. More...


void DoClient (unsigned short Port)
 Create a client, connect it to a running server and start sending him audio data.


const sf::Uint8 AudioData = 1
const sf::Uint8 EndOfStream = 2

Function Documentation

void DoClient ( unsigned short  Port)

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


Definition at line 63 of file Client.cpp.

    // Check that the device can capture audio
    if (sf::SoundRecorder::CanCapture() == false)
        std::cout << "Sorry, audio capture is not supported by your system" << std::endl;

    // Ask for server address
    sf::IPAddress ServerAddress;
        std::cout << "Type address or name of the server to connect to : ";
        std::cin  >> ServerAddress;
    while (!ServerAddress.IsValid());

    // Create a TCP socket for communicating with server
    sf::SocketTCP Socket;

    // Connect to the specified server
    if (Socket.Connect(Port, ServerAddress) != sf::Socket::Done)
    std::cout << "Connected to server " << ServerAddress << std::endl;

    // Wait for user input...
    std::cin.ignore(10000, '\n');
    std::cout << "Press enter to start recording audio";
    std::cin.ignore(10000, '\n');

    // Create a instance of our custom recorder
    NetworkRecorder Recorder(Socket);

    // Start capturing audio data
    std::cout << "Recording... press enter to stop";
    std::cin.ignore(10000, '\n');

    // Send a "end-of-stream" packet
    sf::Packet PacketOut;
    PacketOut << EndOfStream;

    // Close the socket when we're done

Here is the caller graph for this function:

Variable Documentation

const sf::Uint8 AudioData = 1

Definition at line 10 of file Client.cpp.

const sf::Uint8 EndOfStream = 2

Definition at line 11 of file Client.cpp.