aSmack, How to Force a Reconnection?

443 views Asked by At

I Have an aSmack Implemented Application, (8-4.0.5) , as we Know it has an internal Reconnection Management, but its not saticifying, Since some times we should wait 5 minutes to reconnection happenes while we know now is a good time to do so, so i have implemented this:

private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
    intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
               if(isNetworkAvailable()){
                   if(MyService.myServiceInstance!=null){
                       if(!MyService.connection.isConnected() || !MyService.connection.isAuthenticated()){
                           MyService.myServiceInstance.performReconnect();
                          // Which goes to Connect() and Authenticate()
                       }
                   }
                  LMApplication.getInstance().getPresistentJobManager().onNetworkChange(true);
               }

   }
}; 

but the problem is some times they both try to connect ( my manager and built in manager) at the same time , and the result is , they reconnect next time eachother again and again and every time i get this error :

11-10 14:58:09.069: W/PacketWriter(26439): Exception writing closing stream element
11-10 14:58:09.069: W/PacketWriter(26439): java.io.IOException: BufferedWriter is  
closed
11-10 14:58:09.069: W/PacketWriter(26439):  at    
java.io.BufferedWriter.checkNotClosed(BufferedWriter.java:130)
11-10 14:58:09.069: W/PacketWriter(26439):  at   
java.io.BufferedWriter.flush(BufferedWriter.java:122)
11-10 14:58:09.069: W/PacketWriter(26439):  at 
org.jivesoftware.smack.util.ObservableWriter.flush(ObservableWriter.java:44)
11-10 14:58:09.069: W/PacketWriter(26439):  at 
org.jivesoftware.smack.tcp.PacketWriter.writePackets(PacketWriter.java:190)
11-10 14:58:09.069: W/PacketWriter(26439):  at 
org.jivesoftware.smack.tcp.PacketWriter.access$000(PacketWriter.java:40)
11-10 14:58:09.069: W/PacketWriter(26439):  at 
org.jivesoftware.smack.tcp.PacketWriter$1.run(PacketWriter.java:77)

i guess because 1 has already done the job and closes the writer , and the other one see's that the writer is closed , disconnect the connection ! just like 2 jealous kids !

so is there any idea what can i do here , like how can i disable the impact, or force the Reconnection ?

1

There are 1 answers

0
zozelfelfo On BEST ANSWER

I had to remove aSamack autoreconnect system and I did it completely on my own, that way my app gained stability.