Ozgur Ozturk`s Introduction to XMPP 1 XMPP Protocol and
Transkript
Ozgur Ozturk`s Introduction to XMPP 1 XMPP Protocol and
XMPP Protocol and Application Development using Open Source XMPP Software and Libraries Software Access to This Tutorial that you will need to repeat exercises with me • Start downloads now – In the break you will have time to install • Latest version of slides available on • Visual C# 2008 Express Edition – http://DrOzturk.com/talks – http://www.microsoft.com/express/downloads/ • Also useful for clicking on links • Eclipse IDE for Java Developers (92 MB) – http://www.eclipse.org/downloads/ Ozgur Ozturk ozturk@gatech.edu Georgia Institute of Technology, Atlanta, GA • Openfire & Spark Code: – http://www.igniterealtime.org/downloads/source.jsp – TortoiseSVN recommended for subversion check out • http://tortoisesvn.net/downloads Acknowledgement: This tutorial is based on the book “XMPP: The Definitive Guide, Building Real-Time Applications with Jabber Technologies” with permission from Peter Saint-Andre. • JabberNet code: 1 2 • Extensible Messaging and Presence Protocol • IM and Social Networking platforms – GTalk, and Facebook – open, XML-based protocol – aimed at near-real-time, extensible • Collaborative services – Google Wave, and Gradient; • instant messaging (IM), and • presence information. Introduction to XMPP • Geo-presence systems – Nokia Ovi Contacts • Extended with features such as Voice over IP and file transfer signaling • Multiplayer games – Chesspark • Many online live customer support and technical support services. – and even expanded into the broader realm of message-oriented middleware 4 Ozgur Ozturk's Introduction to XMPP 3 Samples from its Usage What is XMPP Part 1 – http://code.google.com/p/jabber-net/ 5 6 1 Overview of Tutorial SIMPLE (contender to XMPP) • • • • Introduction to XMPP IM and Presence requirements, XML Refresher XMPP Extension Protocols (XEPs) Hands on exercises/demonstrations of using some Open Source XMPP Libraries, Clients and Servers • Architecture options & extending XMPP • Talk slides, code and links will be available on http://DrOzturk.com/talks Advantages of XMPP • Open XML standard formalized by IETF • SIMPLE: SIP for Instant Messaging and Presence Leveraging Extensions • SIP: Session Initiation Protocol, established signaling protocol for VOIP and IPTV – Extensible for new service or information types – Implementations with modular/pluggable APIs • Continuously extended through the standards process of the XMPP Standards Foundation • XMPP servers (via federation) form a decentralized network similar to e-mail – anyone (with a domain) can run an XMPP server 7 8 Three Types of XMPP Stanzas Some XMPP Terminology XML Basics • Stanza: Basic unit of communication in XMPP • Libraries abstract away from the XML layer • JabberID (JID): address of XMPP entities – JIDs for users look like email addresses, composed of username, “@” sign and the domain – Bare JID + Resource Identifier = Full JID: • e.g., ozgur7@gmail.com/web-9z2 • Routing traffic to one connection of user, web-client rather than mobile or desktop client (which may be simultaneously connected) – However to extend XMPP we need to know basics • Three types of Stanzas: – Message • method for getting info from one place to another – Presence • availability and status messages of entities – iq (Info/Query) • request-response interactions and simple workflows 10 Ozgur Ozturk's Introduction to XMPP 9 Terminology <?xml version="1.0" encoding="ISO-8859-1"?> <CATALOG> • Entity, Tag <CD> • Schema <TITLE>Unchain my heart</TITLE> <ARTIST NAME="Joe Cocker" /> • DTD, XSD <COUNTRY>USA</COUNTRY> <COMPANY>EMI</COMPANY> • Well-formed <PRICE>8.20</PRICE> • Valid <YEAR>1987</YEAR> </CD> Attribute <!– Add more CD Albums here… --> • Not recommended for data. • Prefer to use element: </CATALOG> <ARTIST> 11 Special Syntax for empty elements, where closing tag would come immediately after opening tag <NAME> Joe Crocker </NAME> </ARTIST> 12 • Recommended for metadata 2 Sample XML Standard: POSLog Same Local Name, Different Qualified Names XML Namespaces Namespaces needed for combining multiple existing vocabularies, to prevent conflict of names. <bk:bookstore xmlns:bk="urn:xmlns:dozturk.com:books"> <bk:book bk:title="Lord of the Rings, Book 3"> <book for=“Ozgur Ozturk“/> </bk:book> </bk:bookstore> Not a URL, just a namespace! Namespaces are not applied to attributes, unless you specify them explicitly. These two are from two vocabularies. One of the <book> tags means reserving. 13 1: Message Stanza 2: Presence Messages • The “push” method for getting information from one place to another <message from="ozgur7@gmail.com/wz2" to="stpeter@jabber.org" type="chat"> from address <body>How are you?</body> •not provided by sending client, <subject>Query</subject> •stamped by the </message> sender’s server •to avoid address spoofing Ozgur Ozturk's Introduction to XMPP 14 2: Presence Stanza • Advertises the network availability and status messages of entities • A specialized publish-subscribe method; people who requested subscription to your presence and authorized by you receive updated presence information when you come online, and go offline, and change your status 16 15 <presence from="ozgur7@gmail.com/android-z2"> <show>do not disturb</show> <status>in a meeting</status> </presence> 17 18 3 3: IQ (Info/Query) Stanza 1/4: Requesting Roster 3: IQ (Info/Query) Messages • Structure for request-response interactions and simple workflows. • Requests and responses are tracked using the id attribute • type attribute included in the exchanged iq stanzas helps in establishing a structured IQ interaction between two entities • Next example: IM client software gets my roster from its server and then updates it <iq 20 3: IQ (Info/Query) Stanza 4/4:Server’s Acknowledgement <iq from="ozgur7@gmail.com/wz2" id="ru761vd7" New transaction, new id. to="ozgur7@gmail.com" type="set"> <query xmlns="jabber:iq:roster"> <item jid="stpeter@jabber.org"/> </query> </iq> 22 Ozgur Ozturk's Introduction to XMPP from="ozgur7@gmail.com" id="rr82a1z7" to="ozgur7@gmail.com/wz2" type="result"> <query xmlns="jabber:iq:roster"> <item jid="frnd1@gmail.com"/> <item jid="spouse@facebook.com"/> </query> • </iq> <iq from="ozgur7@gmail.com/wz2" id="rr82a1z7" to="ozgur7@gmail.com" type="get"> <query xmlns="jabber:iq:roster"/> </iq> 19 3: IQ (Info/Query) Stanza 3/4: Client adds a new contact. 3: IQ (Info/Query) Stanza 2/4: Server Returning Roster 21 15 Minute Break <iq from="ozgur7@gmail.com" Same id with request. id="ru761vd7" to="ozgur7@gmail.com/wz2" type="result“/> Now is the time to install your software When we are back we will code, yay! Each request needs a reply. Even if it is empty 23 24 4 Download Link for .Net XMPP library Download and install Jabber-Net • XMPP Library for .Net (written in C#) http://code.google.com/p/jabber-net/ Part 2 – I recommend to install from source code • So you can trace into the library code upon errors • I will show how to add components to toolbar manually Coding a Basic Client Without re-implementing the wheel: Using Jabber-Net .Net Library 25 26 Visual Studio Toolbox with Jabber-Net MyFirstClient project 28 Ozgur Ozturk's Introduction to XMPP 27 29 30 5 Simplest Client App Five lines of code Voila! Our Weather Bot is Working Double Click • Automatically added events and function templates: • Just fill in the action: 31 32 Extensibility and Available XEPs Data Forms XEP • Specifies how a server sends the information necessary for a client to render a form • Defines several common field types • XMPP is an XML based, extensible protocol • XMPP Standards Foundation (XSF) standardizes extensions to XMPP through a process centered around XMPP Extension Protocols (XEPs) Part 3 XMPP Extension Protocols (XEPs) 33 – boolean, – list options with single or multiple choice, – text with single line or multiple lines, – hidden fields, … – & extensibility for future data types – http://xmpp.org/extensions/ • Related extension: CAPTCHA Forms XEP 34 Ozgur Ozturk's Introduction to XMPP 35 36 6 In-Band Registration XEP Publish-Subscribe XEP & Personal Eventing Protocol (PEP) XEP Multi-User Chat XEP • Presents a more generalized form of the publish/subscribe model than presence • To enable multiple XMPP users to exchange messages in the context of a room or channel • For in-band registration, password change or cancellation of an existing registration • Extensible via use of data forms – similar to Internet Relay Chat (IRC). – communicating “rich presence” such as moods – exchanging “lifestreaming” data, such as microblogs – also applied to storing personal data • Standard chat-room features such as room topics and invitations • A strong room control model, adds ability to: – enables services to gather a wide range of information during the registration process • Bookmarks, client preferences… – kick and ban users – name room moderators and administrators – require membership or passwords to join the room 37 • Further extensions of PEP – User Tune, User Location, and User Activity XEPs 38 Download Links for Client and Server with Pluggable API Multimedia Networking Extensions: Jingle XEP • XMPP as the signaling channel to negotiate, manage & terminate media sessions • OpenFire: XMPP server • Spark: XMPP client • Both are open source Java implementation, with multi-platform support • Openfire & Spark Code: Part 4 – voice/video chat, file transfer, screen sharing… – negote media codecs, bitrates and other parameters related to the voice format to be used, deciding whether TCP or UDP will be used – what IP addresses and ports will be used, etc • Media data itself is sent either p2p or through a media relay. 40 Ozgur Ozturk's Introduction to XMPP 39 Compiling and Customizing Openfire XMPP Server and Spark Chat Client – http://www.igniterealtime.org/downloads/source.jsp – TortoiseSVN recommended for subversion check out • http://tortoisesvn.net/downloads 41 42 7