[Nice] For some reason, my code doesn't actually communicate to my stun server...

Tony Di Croce dicroce at gmail.com
Mon Aug 23 10:01:19 PDT 2010


Hi.

I'm having trouble getting a sample app to actually use my stun server... I
can tell on the server side that my server isn't getting hit... But I am
setting the ip and port here... any ideas?

    td


#include <glib.h>
#include <nice/nice.h>

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

static void cb_candidate_gathering_done( NiceAgent *agent,
                                         guint stream_id,
                                         gpointer data )
{
    printf("cb_candidate_gathering_done()\n");
    fflush(stdout);

    // Get the discovered local candidates...

    GSList* localCandidates = nice_agent_get_local_candidates( niceAgent,
streamId, 1 );

    GSList* current = localCandidates;

    while( current )
    {
        NiceCandidate* candidate = (NiceCandidate*)current->data;

        if( candidate )
        {
            switch( candidate->type )
            {
            case NICE_CANDIDATE_TYPE_HOST:
                printf("NICE_CANDIDATE_TYPE_HOST\n");
                fflush(stdout);
                break;
            case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
                printf("NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE\n");
                fflush(stdout);
                break;
            case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
                printf("NICE_CANDIDATE_TYPE_PEER_REFLEXIVE\n");
                fflush(stdout);
                break;
            case NICE_CANDIDATE_TYPE_RELAYED:
                printf("NICE_CANDIDATE_TYPE_RELAYED\n");
                fflush(stdout);
                break;
            default:
                printf("UNKNOWN CANDIDATE!\n");
                fflush(stdout);
                break;
            };
        }

        current = current->next;
    }

}

[ ... removed empty callback functions ... ]

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


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

    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) );

    [ ... removed some extra callback registration ... ]

    // Configure Stun server information...
    //

    g_object_set( G_OBJECT( niceAgent ), "stun-server", "97.74.202.52", 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_main_loop_unref( mainLoop );

    g_object_unref( niceAgent );

    return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/nice/attachments/20100823/d42e0937/attachment-0001.htm>


More information about the Nice mailing list