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