[libnice] nice_agent_recv example

Philip Withnall philip at tecnocode.co.uk
Tue Nov 4 07:53:40 PST 2014


Hi,

On Tue, 2014-11-04 at 15:42 +0100, Radosław Kołodziejczyk wrote:


> Is there any example code of the simplest use case
> with nice_agent_recv()? Like your example-simple in tree?
> I've seen your articlethat says that nice_agent_recv() should be the
> one used in production, yet I can't find
> any example of peer wotking with this.

Apart from the simple examples in my article, your best bet is the
test-send-recv.c code in libnice. It’s a little convoluted (due to being
a test case), but gives examples of all the methods of sending and
receiving using libnice.

My preferred method would be to get a GSource for the stream you’re
receiving, attach that to the GMainContext, and call
nice_agent_recv_nonblocking() until you get G_IO_ERROR_WOULD_BLOCK in
its callback function.

Philip

> 2014-07-06 15:09 GMT+02:00 Philip Withnall <philip at tecnocode.co.uk>:
>         Hi,
>         
>         As Youness says, you have a couple of options:
>          • Call nice_agent_recv() or nice_agent_recv_messages() in a
>         loop in a
>         separate thread.
>          • Use the NiceInputStream retrieved by
>         nice_agent_get_io_stream(), and
>         call g_pollable_input_stream_create_source(), then attach the
>         GSource
>         that returns to your GMainContext, just as
>         nice_agent_attach_recv()
>         does.
>         
>         This is because the NiceAgent needs to have started receiving
>         packets
>         before it can discover the reflexive candidates, as Youness
>         says.
>         
>         Philip
>         
>         On Fri, 2014-07-04 at 04:21 -0400, Youness Alaoui wrote:
>         > Hi,
>         >
>         >
>         >
>         > I'm not sure how it works as I hadn't implemented that part,
>         but I'm
>         > guessing you need to call nice_agent_recv in order for it to
>         receive
>         > the stun messages and discover the server reflexive and peer
>         reflexive
>         > candidaets. I think you need to create a separate thread
>         that will
>         > continuously call the function or something like that. Maybe
>         have a
>         > look at how the GIO implementation works, it could give you
>         ideas.
>         >
>         >
>         > I hope this helps,
>         > Youness.
>         >
>         >
>         >
>         >
>         > On Mon, Jun 30, 2014 at 8:17 AM, Sudesh Kumar
>         <sudeshbks at gmail.com>
>         > wrote:
>         >         I have tried using the nice_agent_recv function in
>         my code,
>         >         but the problem is I have to use the peer reflexive
>         candidate
>         >         as my selected component. As per the function
>         definition
>         >
>         >
>         >         nice_agent_recv_messages must not be used in
>         combination
>         >         with nice_agent_attach_recv() on the same
>         stream/component
>         >         pair.
>         >
>         >
>         >
>         >         but I can get the peer reflexive candidates only if
>         I attaches
>         >         the stream's component's sockets to the Glib
>         Mainloop Context
>         >         using nice_agent_attach_recv() before gathering the
>         local
>         >         candidates.
>         >
>         >
>         >         Please help me in advance on how to use the
>         nice_agent_recv()
>         >         function.
>         >
>         >
>         >         Thanks & Regards,
>         >         Sudesh
>         >
>         >
>         >         On Mon, Jun 23, 2014 at 7:12 PM, Sudesh Kumar
>         >         <sudeshbks at gmail.com> wrote:
>         >                 Hi,
>         >
>         >
>         >                 I am new to libnice and I am able to execute
>         the
>         >                 examples provided in the package. I can see
>         the
>         >                 nice_agent_attach_recv function is used to
>         read the
>         >                 data from connected peer in all the examples
>         and this
>         >                 is a callback function.
>         >
>         >
>         >                 I want to use the nice_agent_recv function
>         instead of
>         >                 nice_agent_attach_recv, but I am unsure
>         about how to
>         >                 use it.
>         >
>         >
>         >                 Can u please provide me a sample
>         code(possibly editing
>         >                 in simple-example.c) on how to use
>         nice_agent_recv
>         >                 function.
>         >
>         >                 Thanks & Regards,
>         >                 Sudesh
>         >
>         >
>         >
>         >         _______________________________________________
>         >         nice mailing list
>         >         nice at lists.freedesktop.org
>         >         http://lists.freedesktop.org/mailman/listinfo/nice
>         >
>         >
>         >
>         > _______________________________________________
>         > nice mailing list
>         > nice at lists.freedesktop.org
>         > http://lists.freedesktop.org/mailman/listinfo/nice
>         
>         
>         
>         _______________________________________________
>         nice mailing list
>         nice at lists.freedesktop.org
>         http://lists.freedesktop.org/mailman/listinfo/nice
>         
> 
> 
> _______________________________________________
> nice mailing list
> nice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nice

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 213 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/nice/attachments/20141104/243c920a/attachment.sig>


More information about the nice mailing list