libnice使用

libnice是一个ICE实现库。它实现了Interactive Connectivity Establishment (ICE) standard (RFC 5245) 和 the Session Traversal Utilities for NAT (STUN) standard (RFC 5389)。

官网地址:https://libnice.freedesktop.org/

源码git库地址:https://gitlab.freedesktop.org/libnice/libnice/

 

1、下载源码:

git clone https://gitlab.freedesktop.org/libnice/libnice.git

2、编译:

2.1、linux平台下:

它依赖:

 glib >= 2.10
 pkg-config
 gupnp-igd >= 0.1.2 (optional)
 gstreamer-0.10 >= 0.10.0 (optional)
gtk-doc-tools     #autogen.sh需要

 

2.2、编译

k@k-C410:/home/libnice$ ./autogen.sh

k@k-C410:/home/libnice$ ./configure

k@k-C410:/home/libnice$ make

 

3、生成的程序和库

在nice/.libs目录下生成静态库libnice.a、动态库libnice.so
在example目录下生成三个例子程序。

4、例子程序的使用

k@k-C410:/home/libnice/examples$ ./simple-example 0 stunserver.org
Copy this line to remote client:

  Tyyp 33oInvKVEn1Lo6LkVVy6P5 1,2013266431,192.168.10.17,47748,host

Enter remote data (single line, no wrapping):
>

红色部分表示提供给对等端协商时的验证用户名、密码、外网地址,以空格分隔。

 

启动二个实例,就可以开始IM对话了:

第一个控制台:

k@k-C410:/home/libnice/examples$ ./simple-example 0 stunserver.org
Copy this line to remote client:

  Tyyp 33oInvKVEn1Lo6LkVVy6P5 1,2013266431,192.168.10.17,47748,host

Enter remote data (single line, no wrapping):
> h4p1 7M8uL1928RzeRv6cWRDqG8 1,2013266431,192.168.10.17,47758,host

Negotiation complete: ([192.168.10.17]:47748, [192.168.10.17]:47758)

Send lines to remote (Ctrl-D to quit):
> a
>

第二个控制台:

k@k-C410:/home/libnice/examples$ ./simple-example 0 stunserver.org
Copy this line to remote client:

  h4p1 7M8uL1928RzeRv6cWRDqG8 1,2013266431,192.168.10.17,47758,host

Enter remote data (single line, no wrapping):
> Tyyp 33oInvKVEn1Lo6LkVVy6P5 1,2013266431,192.168.10.17,47748,host

Negotiation complete: ([192.168.10.17]:47758, [192.168.10.17]:47748)

Send lines to remote (Ctrl-D to quit):
> a
 

 

 

存在的问题:在linux下,stun服务器地址不能通过域名解析到IP地址。解决方法是,直接用stun服务器的IP地址。本人已向项目提交了补丁包。

 

你可能感兴趣的:(IM)