[Nice] Making sense of it all...

Youness Alaoui youness.alaoui at collabora.co.uk
Mon Aug 23 13:08:53 PDT 2010


I see two problems with your code below
first :
you call nice_agent_add_local_address and you add the "127.0.0.1" address.. this
will cause libnice to bind only to the localhost (127.0.0.1) address, in other
words, only to the 'lo' loopback interface on your system.. that's why you're
not receiving anything, everything gets sent by libnice on the lo interface, so
it never reaches anything other than your own computer!
The nice_agent_add_local_address is to be used if you want libnice to send data
on a specific interface (for example, if you have eth0 and eth1 both connected,
and your application knows for a fact that eth0 is useless, then it could tell
libnice to use only eth1 by adding the local address associated with eth1).
If you do not care, and you just want libnice to try all your local interfaces,
then do not call nice_agent_add_local_address. If you don't call that function,
then libnice will automatically detect all your interfaces and send data through
all of them.

Secondly:
-- g_object_set( G_OBJECT( niceAgent ), "stun-server", "test.com", NULL );
I know you changed the address of the stun server, but maybe the issue here is
the same.. the stun-server property must contain the IP ADDRESS of the stun
server, not its DNS, libnice does not do any kind of DNS resolution, so you'd
have to resolve the STUN server's IP address yourself, and give it to libnice
instead of giving its hostname.
Sorry, this does not appear in the documentation, I will update it to make sure
other people don't do the same mistake in the future.

I hope this helps.
Youness.


On 08/20/2010 08:24 PM, Tony Di Croce wrote:
> 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
> <http://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 --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/nice/attachments/20100823/ab1ddb29/attachment.pgp>


More information about the Nice mailing list