[Nice] Making sense of it all...

Tony Di Croce dicroce at gmail.com
Fri Aug 20 17:24:50 PDT 2010


I've been working on the following test program... My goal for now was just
to see the callbacks fire as I gathered local candidates...

Unfortunately, I must be doing something wrong because my stund server never
gets hit and the only candidate type I detect is HOST...

I'm pretty sure there is something wrong with my code (as opposed to my stun
server) because I can run a stun command line client against my server and
the server gets hit (i know because it prints a bunch of stuff)... Any
ideas?

   td

#include <stdio.h>

extern "C"
{
#include <glib.h>
#include <nice/nice.h>
}

GMainContext* mainContext = NULL;
GMainLoop* mainLoop = NULL;
NiceAgent* niceAgent = NULL;
NiceAddress baseAddress;
guint streamId = 0;
GSList* localCandidates = NULL;

[... cut a bunch of callback functions that just basically printed that they
were called ...]

int main( int argc, char* argv[] )
{
    g_type_init();
    g_thread_init( NULL );


    // Create a glib application context and mainloop bject...
    //

    mainContext = g_main_context_new();

    mainLoop = g_main_loop_new( mainContext, FALSE );


    // Create our main nice agent...
    //

    niceAgent = nice_agent_new( mainContext, NICE_COMPATIBILITY_RFC5245 );


    // Specify which local interface to use...
    //

    nice_address_set_from_string( &baseAddress, "127.0.0.1" );
    nice_agent_add_local_address( niceAgent, &baseAddress );


    // Connect callback functions...
    //

    g_signal_connect( G_OBJECT( niceAgent ),
                      "candidate-gathering-done",
                      G_CALLBACK( cb_candidate_gathering_done ),
                      GUINT_TO_POINTER(1) );

    g_signal_connect( G_OBJECT( niceAgent ),
                      "component-state-changed",
                      G_CALLBACK( cb_component_state_changed ),
                      GUINT_TO_POINTER(1) );

    g_signal_connect( G_OBJECT( niceAgent ),
                      "initial-binding-request-received",
                      G_CALLBACK( cb_initial_binding_request_received ),
                      GUINT_TO_POINTER(1) );

    g_signal_connect( G_OBJECT( niceAgent ),
                      "new-candidate",
                      G_CALLBACK( cb_new_candidate ),
                      GUINT_TO_POINTER(1) );

    g_signal_connect( G_OBJECT( niceAgent ),
                      "new-remote-candidate",
                      G_CALLBACK( cb_new_remote_candidate ),
                      GUINT_TO_POINTER(1) );

    g_signal_connect( G_OBJECT( niceAgent ),
                      "new-selected-pair",
                      G_CALLBACK( cb_new_selected_pair ),
                      GUINT_TO_POINTER(1) );

    g_signal_connect( G_OBJECT( niceAgent ),
                      "reliable-transport-writable",
                      G_CALLBACK( cb_reliable_transport_writable ),
                      GUINT_TO_POINTER(1) );


    // Configure Stun server information...
    //

    g_object_set( G_OBJECT( niceAgent ), "stun-server", "test.com", NULL );
    g_object_set( G_OBJECT( niceAgent ), "stun-server-port", 3478, NULL );


    // Create a "stream" and attach it to our agent...
    //

    streamId = nice_agent_add_stream( niceAgent, 1 );

    g_object_set_data( G_OBJECT( niceAgent ), "id",
GUINT_TO_POINTER(streamId) );


    // Begin the local candidate gathering process...
    //

    nice_agent_gather_candidates( niceAgent, streamId );


    // attach recv callback handler...
    //

    nice_agent_attach_recv( niceAgent,
                            streamId,
                            1,
                            mainContext,
                            cb_nice_recv,
                            GUINT_TO_POINTER(1) );



    // Finally, start the glib MainLoop so we can start receiving events...
    //

    g_main_loop_run( mainLoop );

    while( g_main_loop_is_running( mainLoop ) );

    g_object_unref( niceAgent );

    return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/nice/attachments/20100820/4bd94975/attachment.html>


More information about the Nice mailing list