Client tries to connect via bluebox after disconnect()

Post here all your questions related with SmartFoxServer Java API

Moderators: Bax, Lapo, rjgtav

Client tries to connect via bluebox after disconnect()

Postby stager » 30 Mar 2011, 15:43

Hi,

We observe some strange behavior of client after disconnect() method call. If smartConnect is enabled, client always tries to connect via bluebox right after disconnect() call, even if socket connection can be used.

After some investigation we found that socketConnection.close() always (at least in our configuration) throws an error, onError() method is called and it "thinks" that it should try bluebox connect because "connected" property already had been set to false.

We workaround this problem with the following patch (sorry, I didn't find how I can attach a file to message):

Short description: connectInProgress flag tracks if client is connecting and tryBlueBoxConnection(); in onError() is called only in "connecting" state.

Code: Select all
diff -urN SFS_Java_Client_API.orig\sources\it\gotoandplay\smartfoxclient\SmartFoxClient.java SFS_Java_Client_API\sources\it\gotoandplay\smartfoxclient\SmartFoxClient.java
--- SFS_Java_Client_API.orig\sources\it\gotoandplay\smartfoxclient\SmartFoxClient.java   Thu Feb 11 10:34:20 2010
+++ SFS_Java_Client_API\sources\it\gotoandplay\smartfoxclient\SmartFoxClient.java   Wed Mar 30 13:28:38 2011
@@ -27,6 +27,7 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import net.n3.nanoxml.IXMLElement;
@@ -181,6 +182,7 @@
 
     private Map<Integer, Room> roomList;
     private volatile boolean connected;
+    private AtomicBoolean    connectInProgress = new AtomicBoolean(false);
     private long benchStartTime;
 
     private SysHandler sysHandler;
@@ -1216,11 +1218,14 @@
     {
         if(!connected)
         {
+            connectInProgress.set(true);
             initialize();
             this.ipAddress = ipAdr;
             this.port = port;
 
             socketConnection.connect(ipAdr, port);
+
+            connectInProgress.set(false);
         }
         else
         {
@@ -4536,7 +4541,11 @@
     public void onError(Exception e)
     {
         debugMessage("Socket Error: " + e.getMessage(), e, Level.WARNING);
-        tryBlueBoxConnection();
+
+        if (connectInProgress.getAndSet(false))
+        {
+             tryBlueBoxConnection();
+        }
     }
 
     /*
@@ -4608,4 +4617,4 @@
         SFSEvent sfse = new SFSEvent(SFSEvent.onConnection, params);
         dispatchEvent(sfse);
     }
-}
\ No newline at end of file
+}


Best regards,
Serge.
stager
 
Posts: 12
Joined: 06 May 2009, 11:28

Return to Java2SE / Android Client API

Who is online

Users browsing this forum: No registered users and 1 guest