使用smack库的GCM NoResponseException:在回复超时内没有收到响应 [英] GCM using smack library NoResponseException: No response received within reply timeout

查看:352
本文介绍了使用smack库的GCM NoResponseException:在回复超时内没有收到响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是gcm的新手,我尝试使用Smack API连接到GCM的云连接服务器(XMPP)。
我的代码:

I am new to gcm and I tried to connect to Cloud Connection Server(XMPP) of GCM using Smack API. It was alright at the start, My code:

uid = "123456789";
apiKey = "A**************B";
XMPPTCPConnectionConfiguration.Builder config;
config.setSocketFactory(SSLSocketFactory.getDefault());
    config = XMPPTCPConnectionConfiguration.builder();
    config.setUsernameAndPassword(uid,apiKey);
    config.setServiceName("gcm.googleapis.com");
    config.setHost("gcm.googleapis.com");
    config.setPort(5235);
    config.setDebuggerEnabled(true);
    mConnection = new XMPPTCPConnection(config.build());
    mConnection.setPacketReplyTimeout(10000);
    try {
         mConnection.connect();
         mConnection.login();
        }
   catch (SmackException | IOException | XMPPException e) {
            System.out.println("Exception at SmackCcsClient.init()");
            e.printStackTrace();
        }

但我无法通过最初的握手过程。我首先使用了一些虚拟随机GCMID来测试下游消息,并且它在smack调试窗口中显示,但稍后,相同的代码在原始发送的数据包之后不显示任何内容:原始发送的数据包: p>

But I couldnt get past the initial handshaking process. I used some dummy random GCMIDs to test downstream messaging at first and it was showing up in the smack debug window but later on, the same code shows nothing after the following xml feed as Raw sent packets:

<stream:stream xmlns='jabber:client' to='gcm.googleapis.com'  xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>

我试过了

and i tried

mConnection.login(uid+"@gcm.googleapis.com",apiKey);//even though i assume its next step of the handshake.

控制台打印出以下错误:

Console prints the following errors:

org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 10000ms (~10s). Used filter: No filter used or filter was 'null'.
at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:106)
at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:85)
at org.jivesoftware.smack.SynchronizationPoint.checkForResponse(SynchronizationPoint.java:253)
at org.jivesoftware.smack.SynchronizationPoint.checkIfSuccessOrWait(SynchronizationPoint.java:146)
at org.jivesoftware.smack.SynchronizationPoint.checkIfSuccessOrWaitOrThrow(SynchronizationPoint.java:125)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:837)
at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:360)
at psdc.gcm.SmackCcsClient.init(SmackCcsClient.java:64)
at psdc.gcm.GCMServer.activate(GCMServer.java:44)
at psdc.servlets.Mapper.selectIds(Mapper.java:191)
at psdc.servlets.Mapper.doPost(Mapper.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

Jun 25, 2015 5:36:18 PM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener
WARNING: Connection closed with error
java.io.EOFException: input contained no data
    at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:2965)
    at org.xmlpull.mxp1.MXParser.more(MXParser.java:3003)
    at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1409)
    at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1394)
    at org.xmlpull.mxp1.MXParser.next(MXParser.java:1092)
    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1151)
    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:937)
    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:952)
    at java.lang.Thread.run(Unknown Source)

请帮我解决这个问题,因为我真的无法去这里,无处可去。请告诉我一种方法来检查我的xml请求是否达到google。

Please help me to solve this as i am really stuck with this and nowhere to go.Please tell me a way to check if my xml request reaches google or not.

现在用的SMACK库版本4.1.1

Am using the SMACK library version 4.1.1

推荐答案

使用config.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);解决了我的问题。它定义了要使用的连接的配置。它在服务器支持相同的情况下打开TLS。

Using config.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible); solved my problem. It defines the configuration of the connection to be used.It Turns on TLS if the server supports the same.

请参阅: http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/ org / jivesoftware / smack / ConnectionConfiguration.html

config = XMPPTCPConnectionConfiguration.builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);
        config.setSocketFactory(SSLSocketFactory.getDefault());
        config.setUsernameAndPassword(uid,apiKey);
        config.setServiceName("gcm.googleapis.com");
        config.setHost("gcm.googleapis.com");
        config.setPort(5235);
        config.setDebuggerEnabled(true);
            mConnection = new XMPPTCPConnection(config.build());
            mConnection.setPacketReplyTimeout(10000);

            try {
                mConnection.connect();

希望它可以帮助别人。

这篇关于使用smack库的GCM NoResponseException:在回复超时内没有收到响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆