0
Ich erstellte eine Chat-Anwendung in Android und mit Smack API (4.1.7), um Chat Server zu kommunizieren.SocketException - während Drop Netzwerkverbindung in Smack 4.1.7
In Android-Gerät, wenn ich auf dem Flugmodus oder Wählverbindung Dropped, bekommt Socket
Bitte leitet mich von dieser Ausnahme zu verhindern
W/AbstractXMPPConnection: Connection closed with error
java.net.SocketException: recvfrom failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:592)
at libcore.io.IoBridge.recvfrom(IoBridge.java:556)
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:485)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
at java.io.InputStreamReader.read(InputStreamReader.java:231)
at java.io.BufferedReader.read(BufferedReader.java:325)
at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:41)
at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1515)
at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:992)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:349)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1173)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:952)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:967)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: recvfrom failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.recvfromBytes(Native Method)
at libcore.io.Posix.recvfrom(Posix.java:185)
at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:250)
at libcore.io.IoBridge.recvfrom(IoBridge.java:553)
Dies ist mein Verbindungscode
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setServiceName(UserController.getHost());
configBuilder.setHost(UserController.getHost());
configBuilder.setPort(UserController.getPort());
configBuilder.setSendPresence(true);
configBuilder.setDebuggerEnabled(true);
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
connection = new XMPPTCPConnection(configBuilder.build());
// XMPP Connection Listener monitor
connection.addConnectionListener(new ConnectionListener() {
@Override
public void connected(XMPPConnection connection) {
service.sendConnectionUpdate(WhatTimeGlobal.SERVER_CONNECTED);
}
@Override
public void authenticated(XMPPConnection connection, boolean resumed) {
service.sendConnectionUpdate(WhatTimeGlobal.SERVER_CONNECTED);
}
@Override
public void connectionClosed() {
}
@Override
public void connectionClosedOnError(Exception e) {
if (CommonUtils.isInternetAvailable() && connection != null) {
XMPPService.getInstance().loginIntoServer();
}
}
@Override
public void reconnectionSuccessful() {
Log.i("", "Successfully reconnected to the XMPP server.");
}
@Override
public void reconnectingIn(int seconds) {
Log.i("", "Reconnecting in " + seconds + " seconds.");
}
@Override
public void reconnectionFailed(Exception e) {
XMPPService.getInstance().loginIntoServer();
}
});
// Configure the Auth Mechanism - Current moment set it as PLAIN
configureAuthMethod();
connection.setUseStreamManagement(true);
XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
XMPPTCPConnection.setUseStreamManagementDefault(true);
connection.setPacketReplyTimeout(100000);
Roster roster = Roster.getInstanceFor(connection);
roster.setRosterLoadedAtLogin(false);
connection.connect();
Ich habe bereits Re-connection Manager für diese Klasse hinzugefügt. Und es wird automatisch wieder verbunden. Und ich dachte, es könnten irgendwelche funktionalen Abstürze auftreten – Sujewan