Could Not Connect XMPP Server with smack : EOF Exc

2019-05-14 13:25发布

问题:

java.io.EOFException: no more data available - expected end tag </stream:stream> to close start tag <stream:stream> from line 1, parser stopped on END_TAG seen ...</mechanisms></stream:features>... @1:344
at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:3035)
at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046)
at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1144)
at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:279)
at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

//resources : https://developer.android.com/google/gcm/ccs.html#implement

I have tried the exact code which is given in the android website, but it is throwing the end of file exception which i am thinking as some bug in MXParser(not quite sure though). If smack XMPP library is the problem, Is there any other xmpp library which i can use for GCM CCS ? Could any one please help me fix this . In the below image you can see the end stream tag is not closed but this is how i am receiving the packets.

sent and received packets Output windows:

回答1:

For some reason, I have restarted the machine and it got fixed by itself



回答2:

One possible cause is described here:

You need to send some heartbeat - either at XMPP or TCP level - so your endpoint can detect (or prevent) the closed TCP. Many router/NATs fail to send RST or FIN, just drop the TCP connection.

For example, you may use PingManager (smack-extensions) to implement such a heartbeat.