Connecting via XMPP to Google Cloud Connection Server (http://developer.android.com/google/gcm/ccs.html) for the purpose of sending/receiving notifications to Android devices.
Using AGSXMPP (latest version at time of writing) in a .NET4.5 Console Application to test in.
However, immediately after sending the opening XML - the connection is closed. And I cannot find any explanation.
What is sent:
<stream:stream to='gcm.googleapis.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
Note that in the Google documenation, the stream is self-closed <stream />
where as AGSXMPP hasn't sent this - not sure if it makes a difference.
Using wireshark, I can see the message is sent in a stream, to which Google responds with a TCP Reset - the connection is then closed.
xmpp = new XmppClientConnection
{
UseSSL = true,
UseStartTLS = true,
Server = "gcm.googleapis.com",
ConnectServer = "gcm.googleapis.com",
Port = 5235,
Username = "<SENDER ID>@gcm.googleapis.com",
Password = <KEY>,
AutoResolveConnectServer = false,
SocketConnectionType = SocketConnectionType.Direct,
KeepAlive = true,
};
xmpp.Open();
I'm assuming that even if the other settings are incorrect (such as login) I should at least be able to get past this stream message and establish a connection of sorts.
There was some confusion over this scentence in the Google Documentation:
CCS requires a Transport Layer Security (TLS) connection. That means the XMPP client must initiate a TLS connection.
In relation to agsXMPP, this means UseSSL
and not UseStartTLS
. I had both set to true, but UseStartTLS
sets UseSSL
to false. Google closes the connection on a non-SSL connection. Setting UseStartTLS to false (even though the docs talking about initating with a TLS connection) - will allow a SSL connection to establish, and the connection can setup normally.
Working code:
xmpp = new XmppClientConnection
{
UseSSL = true,
UseStartTLS = false,
Server = "gcm.googleapis.com",
ConnectServer = "gcm.googleapis.com",
Port = 5235,
Username = "<SENDER ID>@gcm.googleapis.com",
Password = <KEY>,
AutoResolveConnectServer = false,
SocketConnectionType = SocketConnectionType.Direct,
KeepAlive = true,
};
xmpp.Open();