Google

libshout documentation

libshout version 1.0.4 - 20000824

example code

The following is a run-through of the example program supplied with libshout - example.c.

First, the libshout header has to be included.


#include <shout/shout.h>

Next, the shout_conn_t structure must be declared.


    shout_conn_t conn;

shout_init_connection() must be called to initialize the conn structure with default values.


    shout_init_connection(&conn);

Now, the conn structure must be filled out with the data for this connection.


    conn.ip = "127.0.0.1";
    conn.port = 8000;
    conn.password = "letmein";

Try to connect.


    if (shout_connect(&conn)) {
        printf("Connected to server...\n");

Here's the read loop:


    while (1) {
        read = fread(buff, 1, 4096, stdin);
        total = total + read;

        if (read > 0) {
            ret = shout_send_data(&conn, buff, read);
            if (!ret) {
                printf("DEBUG: Send error: %i...\n", conn.error);
                    break;
                }
        } else {
            break;
        }

        shout_sleep(&conn);

    }

The code is reading blocks of data, and sending them straight into shout_send_data(). The code also makes sure to break out if there are any problems or if we run out of data to send.

The shout_sleep() call at the end makes sure we're pausing once in a while and not flooding the server. It also makes sure the data is going at the correct rate.

Once the read loops is over, we disconnect:


        shout_disconnect(&conn);

And that's it! Libshout does all the dirty work inside of shout_send_data() so that developers can concentrate on adding cool new features.

The full source for example.c can be found with the libshout distribution in example.c.


copyright © 2000 icecast team

www.icecast.org
team@icecast.org

libshout documentation

libshout version 1.0.4 - 20000824