SlideShare a Scribd company logo
1 of 29
Extensible Messaging and
Presence Protocol (XMPP)
with GCM
What is XMPP?
• Extensible Messaging and Presence Protocol (XMPP) is a
communications protocol based on XML (Extensible Markup
Language).
• Originally named Jabber, the protocol was developed by the Jabber
open-source community in 1999.
Strengths of XMPP
• Open standards: The Internet Engineering Task Force formalized
XMPP as an approved instant messaging and presence technology
under the name of XMPP (the latest specifications are RFC
6120 and RFC 6121). No royalties or granted permissions are required
to implement these specifications.
• History: XMPP technologies have been in use since 1999. Many
implementations of the XMPP standards exist for clients, servers,
components, and code libraries.
Weakness of XMPP
• Does not support Quality of Service (QoS): Assured delivery of
messages has to be built on-top of the XMPP layer.
Architecture of XMPP
In XMPP, a client with a unique name communicates with another
client with a unique name through an associated server. Each client
implements the client form of the protocol, where the server provides
routing capability.
In this case, each client is part of the same domain
(discovery.nasa.guv).
• Servers can also communicate for purposes of routing between
domains (for example, between discovery.nasa.guv and
europa.nasa.guv). Further, gateways can exist for purposes of
translating between foreign messaging domains and protocols.
• Gateways are most often used in this context to translate between
IM protocols (for example, XMPP to Internet Relay Chat [IRC]).
• As an extensible protocol, XMPP is an ideal backbone protocol to
provide universal connectivity among different endpoint protocols.
The XMPP gateway permits the termination of a given client-to-server
session and the initiation of a new session to the target endpoint
protocol (along with the necessary protocol translation).
This example shows an XMPP network with gateways to a
Short Message Service (SMS) domain and an SMTP
domain.
XMPP
• XMPP is a relatively simple protocol that occurs over TCP sockets
using XML messages. Asynchronous communication occurs within
XML streams and with XML stanzas.
• An XML stream is an envelope that encapsulates the exchange of
XML information between two entities. XML streams
communicate XML stanzas, which are discrete units of information.
• For example, XML stanzas are used within XMPP to
communicate messages(text between IM users) as well as presence
information. To illustrate these concepts, look at a simple example of
an IM communication using XMPP between two clients.
This Figure illustrates a simple
conversation between two entities. Note
that at least one server appears within
the conversation (in this case, because
both clients exist within the same
domain, there's exactly one server).
The left client is known as the initiating
entity (it initiates the XMPP
communication between the two
entities). This XML stream uses the to
attribute to identify the receiving
domain (as well as define the XML
namespace).
The receiving client on the right receives
this XML stream and responds with an
XML stream response (in this case, using
the from attribute).
The next step in the XML stream from
figure is communicating messages. This
communication occurs within the
message stanza and includes the source
and destination XMPP addresses (from
and to), the language used, and a
message contained within the body of
the stanza. The peer responds with its
own message, the key difference being
the source and destination XMPP
addresses. Finally, the XML stream is
closed by issuing the stream closure
message (which occurs on both sides of
the connection).
In case of Invalid XML stream or stanza
• Either side can return an error, such as defined below. In this case, the
peer sent an XML stream or stanza that was invalid.
<stream:error>
<xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-
streams'/>
<stream:error>
About GCM Connection Server
• The server side of Google Cloud Messaging (GCM) consists of two
components:
• GCM connection servers provided by Google. These servers take
messages from an app server and send them to a client app running
on a device. Google provides connection servers for HTTP and XMPP
(CCS) (XMPP).
• An application server that you must implement in your environment.
This application server sends data to a client app via the chosen GCM
connection server, using the appropriate XMPP or HTTP protocol.
A full GCM implementation requires both a client implementation and
a server implementation.
Role of the Application Server
Before you can write client apps that use GCM, you must have an application
server that meets the following criteria:
• Able to communicate with your client.
• Able to send properly formatted requests to the GCM connection server.
• Able to handle requests and resend them using exponential back-off.
• Able to store the API key and client registration tokens.
• Able to generate message IDs to uniquely identify each message it sends.
Message IDs should be unique per sender ID.
You'll need to decide which GCM connection server protocol(s) you want to
use to enable your app server to interact with GCM connection servers. Note
that if you want to use upstream messaging from your client applications,
you must use XMPP (CCS).
Choosing a GCM Connection Server Protocol
Currently GCM provides two connection server protocols: HTTP and XMPP (CCS).
Your app server can use them separately or in tandem. XMPP (CCS) messaging
differs from HTTP messaging in the following ways:
• Upstream/Downstream messages
HTTP: Downstream only, cloud-to-device up to 4KB of data.
XMPP (CCS): Upstream and downstream (device-to-cloud, cloud-to-device),
up to 4 KB of data.
• Messaging (synchronous or asynchronous)
HTTP: Synchronous. App servers send messages as HTTP POST requests and
wait for a response. This mechanism is synchronous and blocks the sender from
sending another message until the response is received.
XMPP (CCS): Asynchronous. App servers send/receive messages to/from all
their devices at full line speed over persistent XMPP connections. XMPP (CCS)
sends acknowledgment or failure notifications (in the form of special ACK and
NACK JSON-encoded XMPP messages) asynchronously.
• JSON
HTTP: JSON messages sent as HTTP POST.
XMPP (CCS): JSON messages encapsulated in XMPP messages.
• Plain Text
HTTP: Plain Text messages sent as HTTP POST.
XMPP (CCS): Not supported.
• Multicast downstream send to multiple registration tokens.
HTTP: Supported in JSON message format.
XMPP (CCS): Not supported.
Implementing an XMPP Connection Server
• The Google Cloud Messaging (GCM) Cloud Connection Server (CCS) is an XMPP endpoint
that provides a asynchronous, bidirectional connection to Google servers. The
connection can be used to send and receive messages between your server and your
users' GCM-connected devices.
• You can continue to use the HTTP request mechanism to send messages to GCM servers,
side-by-side with CCS which uses XMPP. Some of the benefits of CCS include:
•The asynchronous nature of XMPP allows you to send more messages with fewer
resources.
•Communication is bidirectional—not only can your server send messages to the
device, but the device can send messages back to your server.
•The device can send messages back using the same connection used for receiving,
thereby improving battery life.
Establishing a Connection
• CCS just uses XMPP as an authenticated transport layer, so you can use most
XMPP libraries to manage the connection.
• The CCS XMPP endpoint runs at gcm-xmpp.googleapis.com:5235. When testing
functionality (with non-production users), you should instead connect to gcm-
preprod.googleapis.com:5236 (note the different port). Regular testing on
preprod (a smaller environment where the latest CCS builds run) is beneficial
both for isolating real users from test code, as well as for early detection of
unexpected behavior changes.
• Note that a connection receives upstream messages destined for its GCM sender
ID, regardless of which environment (gcm or gcm-preprod) it is connected to.
Therefore, test code connecting to gcm-preprod.googleapis.com:5236 should use
a different GCM sender ID to avoid upstream messages from production traffic
being sent over test connections.
Downstream Messages
Once the XMPP connection is established, CCS and your server use normal XMPP
<message> stanzas to send JSON-encoded messages back and forth. The body of
the <message> must be:
<gcm xmlns:google:mobile:data>
JSON payload
</gcm>
The JSON payload for regular GCM messages is similar to what the GCM http endpoint
uses, with these exceptions:
• There is no support for multiple recipients.
• to is used instead of registration_ids.
• CCS adds the field message_id, which is required. This ID uniquely identifies the message
in an XMPP connection. The ACK or NACK from CCS uses the message_id to identify a
message sent from app servers to CCS. Therefore, it's important that this message_id not
only be unique (per sender ID), but always present.
In addition to regular GCM messages, control messages are sent, indicated by the
message_type field in the JSON object. The value can be either 'ack' or 'nack', or 'control'
(see formats below). Any GCM message with an unknown message_type can be ignored by
your server.
For each device message your app server receives from CCS, it needs to send an ACK
message. It never needs to send a NACK message. If you don't send an ACK for a message,
CCS resends it the next time a new XMPP connection is established, unless the message
expires first.
CCS also sends an ACK or NACK for each server-to-device message. If you do not receive
either, it means that the TCP connection was closed in the middle of the operation and
your server needs to resend the messages.
Message with payload — data message
Here is an XMPP stanza containing the JSON message from an app server to CCS:
<message id="">
<gcm xmlns="google:mobile:data">
{
"to":"REGISTRATION_ID", // "to" replaces "registration_ids"
"message_id":"m-1366082849205" // new required field
"data":
{
"hello":"world",
}
"time_to_live":"600",
}
</gcm>
</message>
ACK message
Here is an XMPP stanza containing the ACK/NACK message from CCS to the app server:
<message id="">
<gcm xmlns="google:mobile:data">
{
"from":"REGID",
"message_id":"m-1366082849205"
"message_type":"ack"
}
</gcm>
</message>
Flow Control • Every message sent to CCS receives either an ACK or a
NACK response. Messages that haven't received one
of these responses are considered pending. If the
pending message count reaches 100, the app server
should stop sending new messages and wait for CCS to
acknowledge some of the existing pending messages.
• Conversely, to avoid overloading the app server, CCS
stops sending if there are too many unacknowledged
messages. Therefore, the app server should "ACK"
upstream messages, received from the client
application via CCS, as soon as possible to maintain a
constant flow of incoming messages.
• ACKs are only valid within the context of one
connection. If the connection is closed before a
message can be ACKed, the app server should wait for
CCS to resend the upstream message before ACKing it
again. Similarly, all pending messages for which an
ACK/NACK was not received from CCS before the
connection was closed should be sent again.
Flow of events
• PART A (Registration): Android device sends request to the
Google CCS to register and obtain a RegId.
• PART A: Google CCS responds back with the RegId.
• PART B (Upstream): Device sends a message to CCS server.
• PART B: The message sent in the previous step is relayed
by the Google CCS server to the XMMP server application.
• PART C (Downstream): XMPP sends a downstream
message to the CCS.
• PART C: Google CCS relays the downstream message to
the registered Android device.
Sending downstream messages from the
server
• To address or "target" a downstream message, the app server sets to with the receiving client app's
registration token. You can send notification messages with predefined fields, or custom data messages.
• XMPP Message
<message id="">
<gcm xmlns="google:mobile:data">
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."
}
</gcm>
</message>
Receive and handle messages
• To receive simple downstream messages,
use a service that extends
GcmListenerService to handle messages
captured by GcmReceiver. GcmReceiver
extends WakefulBroadcastReceiver,
guaranteeing that the CPU is awake so
that your listener service can complete its
task.
• By overriding the method
GcmListenerService.onMessageReceived
, you can perform actions based on the
received message.
@Override
public void
onMessageReceived(String from,
Bundle data) {
String message =
data.getString("message");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " +
message);
// ...
}
Send Upstream Messages
• If your app server implements the XMPP Connection Server protocol, it can
receive upstream messages from a user's device to the cloud. To initiate an
upstream message, the client app sends a request containing the following:
• The address of the receiving app server, in the format
SENDER_ID@gcm.googleapis.com.
• A message ID that should be unique per sender ID.
• The message data comprising the key/value pairs of the message's payload.
• When it receives this data, GCM builds an XMPP stanza to send to the app
server, adding some additional information about the sending device and
app.
Send an upstream message from an Android
client app
• Your Android app can send an upstream message using the
GoogleCloudMessaging API to call gcm.send as shown:
private void sendMessage() throws IOException {
Bundle data = new Bundle();
data.putString("my_message", "Hello World");
data.putString("my_action","SAY_HELLO");
String id = Integer.toString(msgId.incrementAndGet());
gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data);
}
Sending an ACK message
• In response to an upstream message like the above, the app server must send an
ACK message containing the unique message ID. If GCM does not recieve an ACK,
it may retry sending the message to the app server.
<message id="">
<gcm xmlns="google:mobile:data">
{
"to":"REGID",
"message_id":"m-123"
"message_type":"ack"
}
</gcm>
</message>
Chat between two devices

More Related Content

What's hot

Congestion control Assignment Help
Congestion control Assignment HelpCongestion control Assignment Help
Congestion control Assignment HelpJosephErin
 
CoAP protocol -Internet of Things(iot)
CoAP protocol -Internet of Things(iot)CoAP protocol -Internet of Things(iot)
CoAP protocol -Internet of Things(iot)Sabahat Nowreen Shaik
 
The constrained application protocol (co ap) part 2
The constrained application protocol (co ap)  part 2The constrained application protocol (co ap)  part 2
The constrained application protocol (co ap) part 2Hamdamboy (함담보이)
 
Keynote: Idiomatic RabbitMQ - Gavin M Roy
Keynote: Idiomatic RabbitMQ - Gavin M RoyKeynote: Idiomatic RabbitMQ - Gavin M Roy
Keynote: Idiomatic RabbitMQ - Gavin M RoyRabbitMQ Summit
 
The constrained application protocol (co ap) part 3
The constrained application protocol (co ap)  part 3The constrained application protocol (co ap)  part 3
The constrained application protocol (co ap) part 3Hamdamboy (함담보이)
 
RabbitMQ and AMQP with .net client library
RabbitMQ and AMQP with .net client libraryRabbitMQ and AMQP with .net client library
RabbitMQ and AMQP with .net client libraryMohammed Shaban
 
Implementation and Performance Analysis of a UDP Binding for SOAP
Implementation and Performance Analysis of a UDP Binding for SOAPImplementation and Performance Analysis of a UDP Binding for SOAP
Implementation and Performance Analysis of a UDP Binding for SOAPDr. Fahad Aijaz
 
clustering and load balancing
clustering and load balancingclustering and load balancing
clustering and load balancingPrabhat gangwar
 
The constrained application protocol (coap) part 3
The constrained application protocol (coap)  part 3The constrained application protocol (coap)  part 3
The constrained application protocol (coap) part 3Hamdamboy (함담보이)
 
The constrained application protocol (coap) part 3
The constrained application protocol (coap)  part 3The constrained application protocol (coap)  part 3
The constrained application protocol (coap) part 3Hamdamboy
 
The constrained application protocol (CoAP)
The constrained application protocol (CoAP)The constrained application protocol (CoAP)
The constrained application protocol (CoAP)Hamdamboy (함담보이)
 
MQ Security Overview
MQ Security OverviewMQ Security Overview
MQ Security OverviewMarkTaylorIBM
 
SMTP Simple Mail Transfer Protocol
SMTP Simple Mail Transfer ProtocolSMTP Simple Mail Transfer Protocol
SMTP Simple Mail Transfer ProtocolSIDDARAMAIAHMC
 

What's hot (18)

CoAP Talk
CoAP TalkCoAP Talk
CoAP Talk
 
Congestion control Assignment Help
Congestion control Assignment HelpCongestion control Assignment Help
Congestion control Assignment Help
 
CoAP protocol -Internet of Things(iot)
CoAP protocol -Internet of Things(iot)CoAP protocol -Internet of Things(iot)
CoAP protocol -Internet of Things(iot)
 
The constrained application protocol (co ap) part 2
The constrained application protocol (co ap)  part 2The constrained application protocol (co ap)  part 2
The constrained application protocol (co ap) part 2
 
Keynote: Idiomatic RabbitMQ - Gavin M Roy
Keynote: Idiomatic RabbitMQ - Gavin M RoyKeynote: Idiomatic RabbitMQ - Gavin M Roy
Keynote: Idiomatic RabbitMQ - Gavin M Roy
 
The constrained application protocol (co ap) part 3
The constrained application protocol (co ap)  part 3The constrained application protocol (co ap)  part 3
The constrained application protocol (co ap) part 3
 
RabbitMQ and AMQP with .net client library
RabbitMQ and AMQP with .net client libraryRabbitMQ and AMQP with .net client library
RabbitMQ and AMQP with .net client library
 
MQTT and CoAP
MQTT and CoAPMQTT and CoAP
MQTT and CoAP
 
Implementation and Performance Analysis of a UDP Binding for SOAP
Implementation and Performance Analysis of a UDP Binding for SOAPImplementation and Performance Analysis of a UDP Binding for SOAP
Implementation and Performance Analysis of a UDP Binding for SOAP
 
Remote method invocation (RMI)
Remote method invocation (RMI)Remote method invocation (RMI)
Remote method invocation (RMI)
 
clustering and load balancing
clustering and load balancingclustering and load balancing
clustering and load balancing
 
The constrained application protocol (coap) part 3
The constrained application protocol (coap)  part 3The constrained application protocol (coap)  part 3
The constrained application protocol (coap) part 3
 
The constrained application protocol (coap) part 3
The constrained application protocol (coap)  part 3The constrained application protocol (coap)  part 3
The constrained application protocol (coap) part 3
 
Intake 37 12
Intake 37 12Intake 37 12
Intake 37 12
 
The constrained application protocol (CoAP)
The constrained application protocol (CoAP)The constrained application protocol (CoAP)
The constrained application protocol (CoAP)
 
MSB-Remote procedure call
MSB-Remote procedure callMSB-Remote procedure call
MSB-Remote procedure call
 
MQ Security Overview
MQ Security OverviewMQ Security Overview
MQ Security Overview
 
SMTP Simple Mail Transfer Protocol
SMTP Simple Mail Transfer ProtocolSMTP Simple Mail Transfer Protocol
SMTP Simple Mail Transfer Protocol
 

Similar to Extensible Messaging and Presence Protocol (XMPP) with GCM

Chat app case study - xmpp vs SIP
Chat app case study - xmpp vs SIPChat app case study - xmpp vs SIP
Chat app case study - xmpp vs SIPGenora Infotech
 
Flex Messeging Services
Flex Messeging ServicesFlex Messeging Services
Flex Messeging Servicesravinxg
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabberl xf
 
Messaging queue - Kafka
Messaging queue - KafkaMessaging queue - Kafka
Messaging queue - KafkaMayank Bansal
 
Unit-4 (1).pptx
Unit-4 (1).pptxUnit-4 (1).pptx
Unit-4 (1).pptxpoonamsngr
 
Unit 3 - Protocols and Client-Server Applications - IT
Unit 3 - Protocols and Client-Server Applications - ITUnit 3 - Protocols and Client-Server Applications - IT
Unit 3 - Protocols and Client-Server Applications - ITDeepraj Bhujel
 
Azure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistAzure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistSalim M Bhonhariya
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of thingsCharles Gibbons
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of thingsCharles Gibbons
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of thingsCharles Gibbons
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of thingsCharles Gibbons
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of thingsCharles Gibbons
 
Internet of Things: Protocols for M2M
Internet of Things: Protocols for M2MInternet of Things: Protocols for M2M
Internet of Things: Protocols for M2MCharles Gibbons
 
How a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdfHow a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdfarccreation001
 
CHP-4.pptx
CHP-4.pptxCHP-4.pptx
CHP-4.pptxFamiDan
 

Similar to Extensible Messaging and Presence Protocol (XMPP) with GCM (20)

Chat app case study - xmpp vs SIP
Chat app case study - xmpp vs SIPChat app case study - xmpp vs SIP
Chat app case study - xmpp vs SIP
 
Flex Messeging Services
Flex Messeging ServicesFlex Messeging Services
Flex Messeging Services
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabber
 
Messaging queue - Kafka
Messaging queue - KafkaMessaging queue - Kafka
Messaging queue - Kafka
 
Unit-4 (1).pptx
Unit-4 (1).pptxUnit-4 (1).pptx
Unit-4 (1).pptx
 
Messaging in Java
Messaging in JavaMessaging in Java
Messaging in Java
 
Unit 3 - Protocols and Client-Server Applications - IT
Unit 3 - Protocols and Client-Server Applications - ITUnit 3 - Protocols and Client-Server Applications - IT
Unit 3 - Protocols and Client-Server Applications - IT
 
Azure Service Bus Performance Checklist
Azure Service Bus Performance ChecklistAzure Service Bus Performance Checklist
Azure Service Bus Performance Checklist
 
How Email Works
How Email WorksHow Email Works
How Email Works
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of things
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of things
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of things
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of things
 
Protocols for internet of things
Protocols for internet of thingsProtocols for internet of things
Protocols for internet of things
 
Internet of Things: Protocols for M2M
Internet of Things: Protocols for M2MInternet of Things: Protocols for M2M
Internet of Things: Protocols for M2M
 
How a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdfHow a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdf
 
Internet
InternetInternet
Internet
 
Transport layer.pptx
Transport layer.pptxTransport layer.pptx
Transport layer.pptx
 
CHP-4.pptx
CHP-4.pptxCHP-4.pptx
CHP-4.pptx
 
CCNA 1 Chapter 10 v5.0 2014
CCNA 1 Chapter 10 v5.0 2014CCNA 1 Chapter 10 v5.0 2014
CCNA 1 Chapter 10 v5.0 2014
 

Recently uploaded

What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Recently uploaded (20)

What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 

Extensible Messaging and Presence Protocol (XMPP) with GCM

  • 1. Extensible Messaging and Presence Protocol (XMPP) with GCM
  • 2. What is XMPP? • Extensible Messaging and Presence Protocol (XMPP) is a communications protocol based on XML (Extensible Markup Language). • Originally named Jabber, the protocol was developed by the Jabber open-source community in 1999.
  • 3. Strengths of XMPP • Open standards: The Internet Engineering Task Force formalized XMPP as an approved instant messaging and presence technology under the name of XMPP (the latest specifications are RFC 6120 and RFC 6121). No royalties or granted permissions are required to implement these specifications. • History: XMPP technologies have been in use since 1999. Many implementations of the XMPP standards exist for clients, servers, components, and code libraries.
  • 4. Weakness of XMPP • Does not support Quality of Service (QoS): Assured delivery of messages has to be built on-top of the XMPP layer.
  • 5. Architecture of XMPP In XMPP, a client with a unique name communicates with another client with a unique name through an associated server. Each client implements the client form of the protocol, where the server provides routing capability. In this case, each client is part of the same domain (discovery.nasa.guv).
  • 6. • Servers can also communicate for purposes of routing between domains (for example, between discovery.nasa.guv and europa.nasa.guv). Further, gateways can exist for purposes of translating between foreign messaging domains and protocols. • Gateways are most often used in this context to translate between IM protocols (for example, XMPP to Internet Relay Chat [IRC]). • As an extensible protocol, XMPP is an ideal backbone protocol to provide universal connectivity among different endpoint protocols. The XMPP gateway permits the termination of a given client-to-server session and the initiation of a new session to the target endpoint protocol (along with the necessary protocol translation).
  • 7. This example shows an XMPP network with gateways to a Short Message Service (SMS) domain and an SMTP domain.
  • 8. XMPP • XMPP is a relatively simple protocol that occurs over TCP sockets using XML messages. Asynchronous communication occurs within XML streams and with XML stanzas. • An XML stream is an envelope that encapsulates the exchange of XML information between two entities. XML streams communicate XML stanzas, which are discrete units of information. • For example, XML stanzas are used within XMPP to communicate messages(text between IM users) as well as presence information. To illustrate these concepts, look at a simple example of an IM communication using XMPP between two clients.
  • 9. This Figure illustrates a simple conversation between two entities. Note that at least one server appears within the conversation (in this case, because both clients exist within the same domain, there's exactly one server). The left client is known as the initiating entity (it initiates the XMPP communication between the two entities). This XML stream uses the to attribute to identify the receiving domain (as well as define the XML namespace). The receiving client on the right receives this XML stream and responds with an XML stream response (in this case, using the from attribute).
  • 10. The next step in the XML stream from figure is communicating messages. This communication occurs within the message stanza and includes the source and destination XMPP addresses (from and to), the language used, and a message contained within the body of the stanza. The peer responds with its own message, the key difference being the source and destination XMPP addresses. Finally, the XML stream is closed by issuing the stream closure message (which occurs on both sides of the connection).
  • 11. In case of Invalid XML stream or stanza • Either side can return an error, such as defined below. In this case, the peer sent an XML stream or stanza that was invalid. <stream:error> <xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp- streams'/> <stream:error>
  • 12. About GCM Connection Server • The server side of Google Cloud Messaging (GCM) consists of two components: • GCM connection servers provided by Google. These servers take messages from an app server and send them to a client app running on a device. Google provides connection servers for HTTP and XMPP (CCS) (XMPP). • An application server that you must implement in your environment. This application server sends data to a client app via the chosen GCM connection server, using the appropriate XMPP or HTTP protocol. A full GCM implementation requires both a client implementation and a server implementation.
  • 13. Role of the Application Server Before you can write client apps that use GCM, you must have an application server that meets the following criteria: • Able to communicate with your client. • Able to send properly formatted requests to the GCM connection server. • Able to handle requests and resend them using exponential back-off. • Able to store the API key and client registration tokens. • Able to generate message IDs to uniquely identify each message it sends. Message IDs should be unique per sender ID. You'll need to decide which GCM connection server protocol(s) you want to use to enable your app server to interact with GCM connection servers. Note that if you want to use upstream messaging from your client applications, you must use XMPP (CCS).
  • 14. Choosing a GCM Connection Server Protocol Currently GCM provides two connection server protocols: HTTP and XMPP (CCS). Your app server can use them separately or in tandem. XMPP (CCS) messaging differs from HTTP messaging in the following ways: • Upstream/Downstream messages HTTP: Downstream only, cloud-to-device up to 4KB of data. XMPP (CCS): Upstream and downstream (device-to-cloud, cloud-to-device), up to 4 KB of data. • Messaging (synchronous or asynchronous) HTTP: Synchronous. App servers send messages as HTTP POST requests and wait for a response. This mechanism is synchronous and blocks the sender from sending another message until the response is received. XMPP (CCS): Asynchronous. App servers send/receive messages to/from all their devices at full line speed over persistent XMPP connections. XMPP (CCS) sends acknowledgment or failure notifications (in the form of special ACK and NACK JSON-encoded XMPP messages) asynchronously.
  • 15. • JSON HTTP: JSON messages sent as HTTP POST. XMPP (CCS): JSON messages encapsulated in XMPP messages. • Plain Text HTTP: Plain Text messages sent as HTTP POST. XMPP (CCS): Not supported. • Multicast downstream send to multiple registration tokens. HTTP: Supported in JSON message format. XMPP (CCS): Not supported.
  • 16. Implementing an XMPP Connection Server • The Google Cloud Messaging (GCM) Cloud Connection Server (CCS) is an XMPP endpoint that provides a asynchronous, bidirectional connection to Google servers. The connection can be used to send and receive messages between your server and your users' GCM-connected devices. • You can continue to use the HTTP request mechanism to send messages to GCM servers, side-by-side with CCS which uses XMPP. Some of the benefits of CCS include: •The asynchronous nature of XMPP allows you to send more messages with fewer resources. •Communication is bidirectional—not only can your server send messages to the device, but the device can send messages back to your server. •The device can send messages back using the same connection used for receiving, thereby improving battery life.
  • 17. Establishing a Connection • CCS just uses XMPP as an authenticated transport layer, so you can use most XMPP libraries to manage the connection. • The CCS XMPP endpoint runs at gcm-xmpp.googleapis.com:5235. When testing functionality (with non-production users), you should instead connect to gcm- preprod.googleapis.com:5236 (note the different port). Regular testing on preprod (a smaller environment where the latest CCS builds run) is beneficial both for isolating real users from test code, as well as for early detection of unexpected behavior changes. • Note that a connection receives upstream messages destined for its GCM sender ID, regardless of which environment (gcm or gcm-preprod) it is connected to. Therefore, test code connecting to gcm-preprod.googleapis.com:5236 should use a different GCM sender ID to avoid upstream messages from production traffic being sent over test connections.
  • 18. Downstream Messages Once the XMPP connection is established, CCS and your server use normal XMPP <message> stanzas to send JSON-encoded messages back and forth. The body of the <message> must be: <gcm xmlns:google:mobile:data> JSON payload </gcm>
  • 19. The JSON payload for regular GCM messages is similar to what the GCM http endpoint uses, with these exceptions: • There is no support for multiple recipients. • to is used instead of registration_ids. • CCS adds the field message_id, which is required. This ID uniquely identifies the message in an XMPP connection. The ACK or NACK from CCS uses the message_id to identify a message sent from app servers to CCS. Therefore, it's important that this message_id not only be unique (per sender ID), but always present. In addition to regular GCM messages, control messages are sent, indicated by the message_type field in the JSON object. The value can be either 'ack' or 'nack', or 'control' (see formats below). Any GCM message with an unknown message_type can be ignored by your server. For each device message your app server receives from CCS, it needs to send an ACK message. It never needs to send a NACK message. If you don't send an ACK for a message, CCS resends it the next time a new XMPP connection is established, unless the message expires first. CCS also sends an ACK or NACK for each server-to-device message. If you do not receive either, it means that the TCP connection was closed in the middle of the operation and your server needs to resend the messages.
  • 20. Message with payload — data message Here is an XMPP stanza containing the JSON message from an app server to CCS: <message id=""> <gcm xmlns="google:mobile:data"> { "to":"REGISTRATION_ID", // "to" replaces "registration_ids" "message_id":"m-1366082849205" // new required field "data": { "hello":"world", } "time_to_live":"600", } </gcm> </message>
  • 21. ACK message Here is an XMPP stanza containing the ACK/NACK message from CCS to the app server: <message id=""> <gcm xmlns="google:mobile:data"> { "from":"REGID", "message_id":"m-1366082849205" "message_type":"ack" } </gcm> </message>
  • 22. Flow Control • Every message sent to CCS receives either an ACK or a NACK response. Messages that haven't received one of these responses are considered pending. If the pending message count reaches 100, the app server should stop sending new messages and wait for CCS to acknowledge some of the existing pending messages. • Conversely, to avoid overloading the app server, CCS stops sending if there are too many unacknowledged messages. Therefore, the app server should "ACK" upstream messages, received from the client application via CCS, as soon as possible to maintain a constant flow of incoming messages. • ACKs are only valid within the context of one connection. If the connection is closed before a message can be ACKed, the app server should wait for CCS to resend the upstream message before ACKing it again. Similarly, all pending messages for which an ACK/NACK was not received from CCS before the connection was closed should be sent again.
  • 23. Flow of events • PART A (Registration): Android device sends request to the Google CCS to register and obtain a RegId. • PART A: Google CCS responds back with the RegId. • PART B (Upstream): Device sends a message to CCS server. • PART B: The message sent in the previous step is relayed by the Google CCS server to the XMMP server application. • PART C (Downstream): XMPP sends a downstream message to the CCS. • PART C: Google CCS relays the downstream message to the registered Android device.
  • 24. Sending downstream messages from the server • To address or "target" a downstream message, the app server sets to with the receiving client app's registration token. You can send notification messages with predefined fields, or custom data messages. • XMPP Message <message id=""> <gcm xmlns="google:mobile:data"> { "data": { "score": "5x1", "time": "15:10" }, "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..." } </gcm> </message>
  • 25. Receive and handle messages • To receive simple downstream messages, use a service that extends GcmListenerService to handle messages captured by GcmReceiver. GcmReceiver extends WakefulBroadcastReceiver, guaranteeing that the CPU is awake so that your listener service can complete its task. • By overriding the method GcmListenerService.onMessageReceived , you can perform actions based on the received message. @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); Log.d(TAG, "From: " + from); Log.d(TAG, "Message: " + message); // ... }
  • 26. Send Upstream Messages • If your app server implements the XMPP Connection Server protocol, it can receive upstream messages from a user's device to the cloud. To initiate an upstream message, the client app sends a request containing the following: • The address of the receiving app server, in the format SENDER_ID@gcm.googleapis.com. • A message ID that should be unique per sender ID. • The message data comprising the key/value pairs of the message's payload. • When it receives this data, GCM builds an XMPP stanza to send to the app server, adding some additional information about the sending device and app.
  • 27. Send an upstream message from an Android client app • Your Android app can send an upstream message using the GoogleCloudMessaging API to call gcm.send as shown: private void sendMessage() throws IOException { Bundle data = new Bundle(); data.putString("my_message", "Hello World"); data.putString("my_action","SAY_HELLO"); String id = Integer.toString(msgId.incrementAndGet()); gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data); }
  • 28. Sending an ACK message • In response to an upstream message like the above, the app server must send an ACK message containing the unique message ID. If GCM does not recieve an ACK, it may retry sending the message to the app server. <message id=""> <gcm xmlns="google:mobile:data"> { "to":"REGID", "message_id":"m-123" "message_type":"ack" } </gcm> </message>
  • 29. Chat between two devices