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地址。本人已向项目提交了补丁包。

 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值