[libnice] Using TURN to enable UDP P2P Communication

Olivier Crête olivier.crete at collabora.com
Thu Aug 14 21:59:04 PDT 2014


On 08/15/2014 12:05 AM, Scott Richmond wrote:
> 1. If I used UDP STUN to bash open some ports between two peers, what
> will typically keep the NAT port map in place on the users routers? Do
> they typically wait for a FIN or RST to flow over the open port before
> closing it?

Since UDP base protocols don't have a "connection" with an end, NAT
routers just have a timeout, if they haven't received packets for a
certain amount of time (typically 30 seconds to 2 minutes), they declare
the connection dead and close it.

> 2. Would this work: I use libnice to open UDP ports between two peers
> with the use of a rendezvous server. I then kill the libnice
> process/instance and for the peer that is running the multiplayer server
> I tell it to listen on that port for incoming connections. Presumably
> the remote peer should be able to connect through to the listening game
> server instance with the previously opened ports from libnice. Would
> this be correct?

This will work with some caveats:
1. If you want to use a TURN relay server (to go from 95% connectivity
to 100%), then everything needs to go through libnice.
2. You need to make sure your application sends a packet at least every
20-30 seconds, the easiest way to do that is to add a no-op packet to
your protocol.
3. You can also use nice_agent_get_selected_socket() to extract the file
descriptor, but that also fails with a relay server.
4. If you want to re-open the same port but not the socket, make sure
you set SO_REUSEADDR on both the socket from libnice and the one in your

> 3. Anyone know of any active C# wrappers for libnice? We can do it
> ourselves, but just curious.

Not that I know of, but I assume the same stuff used for Gtk# may be useful.

Olivier Crête
olivier.crete at collabora.com

More information about the nice mailing list