4

I am establishing connection with openfire using smack api at client side. able to generate successful connection and can chat.but after chatting some time I am getting the following exception.

AbstractXMPPConnection: Connection closed with error
java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:545)
at libcore.io.IoBridge.recvfrom(IoBridge.java:509)
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
at crittercism.android.m.read(Unknown Source)
at java.io.InputStreamReader.read(InputStreamReader.java:233)
at java.io.BufferedReader.read(BufferedReader.java:325)
at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1506)
at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:986)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:346)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
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(Thread.java:841)
Caused by: libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
at libcore.io.Posix.recvfromBytes(Native Method)
at libcore.io.Posix.recvfrom(Posix.java:141)
at libcore.io.BlockGuardOs.recvfrom(BlockGua

Gone through couple answers to the related posts but did not find the actual reason for this exception in my scenario. I am using the below code for establishing connection with openfire :

try { XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                    .setUsernameAndPassword(userName+Constants.openFireIP, password)
                    .setServiceName("182.**.***.**")
                    .setHost("182.**.***.**")
                    .setPort(5222)
                    .setResource("/Smack")
                    .build();
            connecton = new XMPPTCPConnection(config);
            System.out.println("connecton ######## "+connecton);
            makeConnectionAvailable();
        }
        catch(Exception e){
            System.out.println("Exception "+e.getMessage());
            e.printStackTrace();
        } 


public void makeConnectionAvailable(){
    try{
        if(!connecton.isConnected()){
            connecton.connect();
            connecton.login();
            connecton.addConnectionListener(connectionListener);
        }else if(!connecton.isAuthenticated()){
            connecton.login();
        }
}

catch (Exception e){
        e.printStackTrace();
    }

}

Because of this connection becomes terminated and loosing incoming chat messages till i made connection again. let me know if anybody resolve this kind of problem.

Chandra Kiran
  • 299
  • 1
  • 6
  • 14

0 Answers0