<br>Hi.<br><br>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?<br><br>
td<br><br><br><span style="font-family: courier new,monospace;">#include <glib.h></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#include <nice/nice.h></span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">GMainContext* mainContext = NULL;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">GMainLoop* mainLoop = NULL;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">NiceAgent* niceAgent = NULL;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">NiceAddress baseAddress;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">guint streamId = 0;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">GSList* localCandidates = NULL;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">static void cb_candidate_gathering_done( NiceAgent *agent,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> guint stream_id,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> gpointer data )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> printf("cb_candidate_gathering_done()\n");</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> fflush(stdout);</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Get the discovered local candidates...</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> GSList* localCandidates = nice_agent_get_local_candidates( niceAgent, streamId, 1 );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> GSList* current = localCandidates;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> while( current )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> NiceCandidate* candidate = (NiceCandidate*)current->data;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if( candidate )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> switch( candidate->type )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> case NICE_CANDIDATE_TYPE_HOST:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf("NICE_CANDIDATE_TYPE_HOST\n");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fflush(stdout);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> break;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf("NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE\n");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fflush(stdout);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> break;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf("NICE_CANDIDATE_TYPE_PEER_REFLEXIVE\n");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fflush(stdout);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> break;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> case NICE_CANDIDATE_TYPE_RELAYED:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf("NICE_CANDIDATE_TYPE_RELAYED\n");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fflush(stdout);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> break;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> default:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> printf("UNKNOWN CANDIDATE!\n");</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fflush(stdout); </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> break;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> current = current->next;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">[ ... removed empty callback functions ... ]</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">int main( int argc, char* argv[] )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> g_type_init();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> g_thread_init( NULL );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Create a glib application context and mainloop object...</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> mainContext = g_main_context_new();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> mainLoop = g_main_loop_new( mainContext, FALSE );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Create our main nice agent...</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> niceAgent = nice_agent_new( mainContext, NICE_COMPATIBILITY_RFC5245 );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Specify which local interface to use...</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> nice_address_set_from_string( &baseAddress, "127.0.0.1" );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> nice_agent_add_local_address( niceAgent, &baseAddress );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> // Connect callback functions...</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> g_signal_connect( G_OBJECT( niceAgent ),</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> "candidate-gathering-done",</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> G_CALLBACK( cb_candidate_gathering_done ),</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> GUINT_TO_POINTER(1) );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> [ ... removed some extra callback registration ... ]</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Configure Stun server information...</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> //</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> g_object_set( G_OBJECT( niceAgent ), "stun-server", "97.74.202.52", NULL );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> g_object_set( G_OBJECT( niceAgent ), "stun-server-port", 3478, NULL );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Create a "stream" and attach it to our agent...</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> streamId = nice_agent_add_stream( niceAgent, 1 );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> g_object_set_data( G_OBJECT( niceAgent ), "id", GUINT_TO_POINTER(streamId) );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Begin the local candidate gathering process...</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> nice_agent_gather_candidates( niceAgent, streamId );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // attach recv callback handler...</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> nice_agent_attach_recv( niceAgent,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> streamId,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> mainContext,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> cb_nice_recv,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> GUINT_TO_POINTER(1) );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // Finally, start the glib MainLoop so we can start receiving events...</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> //</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> g_main_loop_run( mainLoop );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> while( g_main_loop_is_running( mainLoop ) );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> g_main_loop_unref( mainLoop );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> g_object_unref( niceAgent );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return 0;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;">
<br>