通过XMPP连接到谷歌云连接服务器(http://developer.android.com/google/gcm/ccs.html),以便向安卓设备发送/接收通知。
在.NET4.5控制台应用程序中使用AGSXMPP (编写本文时的最新版本)进行测试。
但是,在发送打开的XML之后,连接立即关闭。我找不到任何解释。
发送内容:
<stream:stream to='gcm.googleapis.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>请注意,在谷歌文档中,流是自关闭的<stream />,而AGSXMPP没有发送这个-不确定它是否会有所不同。
使用wireshark,我可以看到消息是以流的形式发送的,Google以TCP重置作为响应-然后关闭连接。
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();我假设即使其他设置不正确(例如登录),我至少应该能够通过该流消息并建立某种连接。
发布于 2013-07-17 01:24:13
在Google文档中有一些关于这方面的混淆:
TLS需要传输层安全(
)连接。这意味着XMPP客户端必须发起TLS连接。
对于agsXMPP,这意味着UseSSL,而不是UseStartTLS。我将两者都设置为true,但是UseStartTLS将UseSSL设置为false。Google关闭非SSL连接上的连接。将UseStartTLS设置为false (即使文档中提到使用TLS连接进行初始化)-将允许建立SSL连接,并且连接可以正常建立。
工作代码:
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();https://stackoverflow.com/questions/17679389
复制相似问题