实例介绍
权威的Google整理出来的libjingle开发文档,非常方便的实现p2p的文件、语音、视频传输。
bingle developer Guide The libjingle SDK consists of C++ source code and documentation that enable you to design applications that connect and exchange data across a network(peer to peer data connections ). The SDK contains code and sample applications, a Visual Studio 2005 solution file for compiling on Windows computers, configuration and makefiles for other operating systems and compilers, and compilation instructions. Note that the code has some external dependencies(for instance, the voice chat sample has dependencies on Linphone or GlPS VoiceEngine Lite, depending on your platform). Dependencies are ndicated in the code and the build instructions The code includes network and proxy negotiation classes XML parsing classes a stun server, and all the code required to initiate connections and exchange data between two computers. The connection code enables applications to robustly traverse NaT and firewall devices using the ICe mechanism, to use STUN servers, and to exchange either UDP or tCP data packets. You can use the code as provided or extend it fit your own specific needs, according to the Berkeley-style license Jingle and libjingle libjingle was created at about the same time as the Jingle XMPP extension(XEP-0166). The libjingle team created their own protocol to handle session negotiation, and later worked with the XMPP Standards Foundation to standardize Jingle; thus, although the libjingle protocol and Jingle are very similar, they are not the same, and are not interoperable The current version of the libjingle code still uses the original internal protocol, which is slightl different from, and incompatible with, the Jingle specification. Nevertheless, it is close enough to Jingle that it is worthwhile learning the Jingle specifications. Similar"close but not identical conditions exist for libjingle's audio content description(early version of Jingle Audio Content Description Format XEP-0167), ICE transport description(carly version of ingle Ice Transport XEP-0176), and raw UDP transport description (early version of Jingle raw UDP transport description XEP-0177). Where this documentation refers to"Jingle"or one of its related extensions (in terms of how libjingle uses that protocol), it really refers to the original, internal protocol The libjingle team intends to implement the official Jingle extension in libjingle(while making libjingle backward compatible for the current custom version) Prerequisites In order to use libjingle, you should be familiar with the XMPP protocol, general networking concepts and C++. Additionally, it helps to be familiar with the Jingle proposed extension(XEP-0166), and other related extensions listed in Jingle and libjingle above The requirements to build and use libjingle are given in Creating a libjingle Application Organization of the documentation This documentation includes the following main topics Important Concepts Describes some of the key concepts in libjingle. Very important if this is your first experience with libjingle Generic libjingle Applications Provides an overview of the main components of a libjingle application, and some specifics about how a generic libjingle application creates a peer-to-peer connection Creating a libjingle Application Describes the key tasks that every libjingle application must perform Sample applications Describes how to build and run the sample applications included with the SDK. Also includes detailed information about how these applications work Reference a reference guide to the important libjingle classes Organization of the sdK The libjingle SDK contains the following folders Directory Description b ase Classes for low-level base functionality such as sockets and threads. Both the p2p and se examples/ Contains two sample applications built on libjingle: call, and file share. There are ot applications p Classes in libjingle's Peer to Peer component, which negotiate. establish, and maintai configuration regardless of nat-enabled devices and firewalls session Classes that specializes the behavior of the basic peer to peer session according to wha third party/ The default folder to hold various third-party extensions needed by the code. For examp installed here to use in the voice chat sample application xmllite/ Classes for parsing and building XMPP stanzas Xmpp. Classes for sending and receiving XMPP requests, and managing common XMPP server Notes libjingle has some issues you should be aware of libjingle code is a work in progress. It is not perfect, complete, or flawless. Some aspects of the code, such as password protection, are not securely implemented, and others, such as URL parsing, are not as robust as they should be. Many, but not all, of these issues are commented in the code. Be sure to code your application as robustly as possible. See Terms and Conditions for the legal mumbo jumbo The example code uses Ssl to transmit the password from the client to the XMPP server however, it does not provide any additional security (except turning off screen echo) to protect the password on the client Version Changelist The following changes have been made to succeeding versions of the libjingle SDK 0.52( January11,2011) Fixed build on windows 7 with vs 2010 Fixed build on windows x64 Fixed build on mac osx Added an option to the examples/call" to enable encrypted calls mproved logging · Bug fixes 0.5.1( November2,2010) Added support for call encryption Added addtional xeP-166 and xep-167 features o Call redirection o Candidates in session-accept or session-initiate Added support for bandwidth control Added features in examples/call o Bandwidth control on initiate or accept Turn on/off ssl Control signaling pr o Send chat message 0. 5.0(September 16, 2010 Implemented Jingle protocols XEP-166 and XEP-167 Backward compatible with Google Talk Call Signaling protocol implemented in previous versions Builds on windows Linux, and mac os x with swtoolkit Removed GipsliteMediaEngine Added video support Added FileMediaEngine to support both voice and video via RtP dump Many bug fixes 04.0( February1,2007) Updated p2p sample code - The tunnel session client example was replaced by a file sharing sample that uses Http protocol to exchange files New peer to peer stack -- The data pathway has been modified, with the removal of the P2PSocket class, and addition of other helper classes (P2P Socket has been replaced by an additional layer of abstraction, managed by Transport. Removal of Session Message- Session Message, a class that was used to wrap custom XML data in the session negotiation channel, has been removed. All session-specific information(such as file names and codecs)are now delivered as raw XML stanzas to the Session Client and Session objects Proxy support -- New code has been added to detect and support proxies automatically. See base/proxydetect, base/autodetectproxy, and base/socketadapters for details Threading changes o Anew base class to create threaded objects has been created. This class signalthread, runs on its own thread, emits a signal when done, and destroys o The file sharing application, unlike the tunnel sharing application, is single-threaded New stream wrapper files--libjingle 0.4.0 now includes several new stream wrapper classes to provide additional i/o functionality New classes include Tar Stream to read and write tar files, and stream Counter to count the number of bytes read or written in a stream Important Concepts You should understand the following important concepts about libjingl Signals Threads and messages Naming Conventions SSL Support Connections Transports, Channels, and Connections Candidates Data packets 1gnals libjingle uses the sigslot library to facilitate communication between objects. sigslot is a generic framework that enables you to connect a calling member to a receiving function in any class (including the same class)very simply. The way it works is this The sending class declares a member variable, called a signal, using a special template-like syntax. This signal defines the parameters of the listening function The listening class implements a function with the same number, type, and sequence of parameters as the signal. This is sometimes called the receiver or the slot. (Note: this can even be the same class as the one that declared the signal. ) This function cannot return a value(e. g, returns void). The receiver must inheritsigslot:: has slots<> The listener connects to the signal by calling the signal's connect method, passing in a pointer to the instance of the listening object, and the address of the implementing class function The sender calls its signal member as if it were a function, passing in the appropriate parameter types as declared. It can pass parameters by either value or reference You can connect as many signals as you like to a common slot libjingle sometimes assigns multiple signals to a single slot in order to consolidate its message handling. Conversely, several objects declare a signal object in order to broadcast commonly needed messages from a single point (for example, lerts sent when a connection state changes ). sigslct takes care of disconnecting callbacks and dereferencing when objects are destroyed The following code demonstrates using sigslot 7/ Class that sends the notification class sender I The signal declaration The 2 in the name indicates the number of parameters. Parameter yres // are declared in the template parameter list sigslot: : signal2<string message, std: time t time> SignalDangeri When anyone calls Panic(), we will send the SignalDanger signal void Panic()[ SignalDanger("Help!, std: time(0))i // Listening class. It must inherit sigslot class Receiver public sigslot:: has s_ots<>t Receiver registers to get SignalDanger signals //When SignalDanger is sent, it is caught by OnDanger( / Second parameter gives address of the listener function class definition // First parameter points to instance of this class to receive notifications Receiver(sender sender sender->SignalDanger connect(this, &Receiver. OnDanger)i / When anyone calls Panic(), Receiver:: On Danger gets the message Notice that the number and type of parameters match // those in Sender:: SigralDanger, and that it doesn't return a value void OnDanger(string message, std::: time t time)I 三( message=="He1p!") //Call the police Many classes in the code send signals to notify listeners of important events. For example, Call: SignalSession State sends notifications when you send or receive a connection attempt Your application must connect to these signals and act appropriately The general convention in libjingle code is to prefix the name of a signal with Signal: e. g SignalState Change, SignalSession State, SignalSession Create. Listener methods intended to connect to signals are typically prefixed with On, e.g., On PortDestroyedo, OnOutgoing MessageO On SendPacko See the sigslot documentation for more details. Threads libjingle supports multithreading in order to improve the performance of your application. libjingle components use one or two globally available threads 【实例截图】
【核心代码】
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论