[Nice] patch: nice_agent_get_selected_socket

Bryce Allen ballen at ci.uchicago.edu
Thu Nov 14 13:33:59 PST 2013

We're using libnice to add ICE support to an existing application.
Rewriting it so application data flows through libnice would be a lot
of work, so currently we destroy the nice agent and bind to the
address and port it discovered. The application uses UDT,
which has it's own keep alives that maintain any intermediate
NAT/firewall state. Unfortunately in Windows Vista and later, binding
to a specific port triggers the firewall prompt.

The attached patch adds a function exposing the underlying socket, which
allows us to duplicate the socket before destroying the nice
agent. We've tested this and it avoids triggering the firewall prompt. I
think it could be useful for other users integrating with legacy

In our case we use the fileno field of GSocket to get the underlying
handle, then use dup/WSADuplicateSocket. Exposing the GSocket seems
like the right level of abstraction though. I guess another option
would be to make NiceSocket public, then users can cast
NiceCandidate.sockptr to NiceSocket and use it to get GSocket etc.



 * nice_agent_get_selected_socket:
 * @agent: The #NiceAgent Object
 * @stream_id: The ID of the stream
 * @component_id: The ID of the component
 * @local: The local socket of the selected pair
 * Retreive the local socket associated with the selected candidate pair
 * for media transmission for a given stream's component.
 * This is useful for adding ICE support to legacy applications that already
 * have a protocol that maintains a connection. If the socket is duplicated
 * before unrefing the agent, the application can take over and continue to use
 * it. New applications are encouraged to use the built in libnice stream
 * handling instead and let libnice handle the connection maintenance.
 * Returns: %TRUE on success, %FALSE if there is no selected candidate pair
 * Since: 0.1.5
nice_agent_get_selected_socket (
  NiceAgent *agent,
  guint stream_id,
  guint component_id,
  GSocket **socket);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: get-selected-socket.diff
Type: text/x-patch
Size: 3164 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/nice/attachments/20131114/72f95eff/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/nice/attachments/20131114/72f95eff/attachment.pgp>

More information about the nice mailing list