Socket Error -> kill client for ever

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error -> kill client for ever

Postby Lapo » 29 Jun 2012, 10:47

tgwozdz wrote:Does anyone have a solution to this problem? I'm seeing something similar:
- Try to connect to server which is offline. I see the security error message in the console for the SWF, but my OnConnection callback is never called with a failure.
- After disabling bluebox, I can now receive the OnConnection callback with a failure response.

This has been very well tested before releasing version 1.0.3 API and it does work.
In fact I am not able to reproduce your problem. If I connect to a machine where SFS is not running I do get the onConnection error.

This is my settings:

Code: Select all

<SmartFoxConfig>
   <!-- Mandatory Settings -->
   <ip>192.168.0.6</ip>
   <port>9933</port>
   <zone>SimpleChat</zone>
   <!-- End Mandatory Settings -->
   
   <debug>true</debug>
   
   <!-- For generic http port communication -->
   <httpPort>8080</httpPort>
   <useBlueBox>true</useBlueBox>
   <blueBoxPollingRate>500</blueBoxPollingRate>
   
</SmartFoxConfig>


And this is the result:
Schermata 2012-06-29 a 12.39.51.png
Screenshot
(43.04 KiB) Not downloaded yet
Lapo
--
gotoAndPlay()
...addicted to flash games
tgwozdz
Posts: 17
Joined: 22 Jun 2012, 15:36

Re: Socket Error -> kill client for ever

Postby tgwozdz » 29 Jun 2012, 12:36

What if you try it from a web browser, as rjgtav suggested? Quote:
Hmm this is strange... Apparently that bug only happens on the browser... If I test the app on the Flash IDE, it always works, with no problems...
Will continue investigating...

[Update]
If I use the debug player WIN 11,2,202,228 on Chrome, it works flawlessly. But the common player (same version) hangs after the first connection error.
On IE, even the debug player gives problems...


I definitely see the issue here locally, using the latest client and server.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error -> kill client for ever

Postby Lapo » 29 Jun 2012, 13:53

Absolutely no difference in the browser.
Tested under Chrome 20.x, Firefox 13.x, Safari 5.x and Opera 11.x
Flash Player 10.x and 11,x

What browser and Flash Player versions do you use?
Lapo

--

gotoAndPlay()

...addicted to flash games
Nelez
Posts: 1
Joined: 03 Jul 2012, 10:24

Re: Socket Error -> kill client for ever

Postby Nelez » 03 Jul 2012, 10:30

I also have the same problem. When testing from the debug player (EXE) from FDT the sfs.killConnection really kills the connection and removes the player from the SmartfoxServer.
When testing in the browser (latest IE, Chrome and FF tested) the user stays a user in SFS (although the onconnectionlost events does get called in the client).
I'm using the latest flash plugins, the latest SFS (2.1) and the latest flash API (1.0.3).

Anyone had any luck?
tgwozdz
Posts: 17
Joined: 22 Jun 2012, 15:36

Re: Socket Error -> kill client for ever

Postby tgwozdz » 11 Jul 2012, 13:34

What browser and Flash Player versions do you use?


I'm using Chrome 20.0.1132.47 on Windows, using Shockwave Flash 11.2 r202 Version: 11,2,202,221 debug player. I can reproduce this probem 100% of the time when bluebox is enabled. If its disabled, it works fine.

When bluebox is enabled, I also see this in the console output:
## SecurityError: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Security sandbox violation: http://dev.foo.com/game/static/tomg/game.swf cannot load data from localhost:9933."]
Error: Request for resource at xmlsocket://localhost:9933 by requestor from http://dev.foo.com/game/static/tomg/game.swf has failed because the server cannot be reached.

*** Security Sandbox Violation ***
Connection to localhost:9933 halted - not permitted from http://dev.foo.com/game/static/tomg/game.swf
Warning: Failed to load policy file from http://localhost:8080/crossdomain.xml

*** Security Sandbox Violation ***
Connection to http://localhost:8080/BlueBox/BlueBox.do halted - not permitted from http://dev.foo.com/game/static/tomg/game.swf
Error: Request for resource at http://localhost:8080/BlueBox/BlueBox.do by requestor from http://dev.foo.com/game/static/tomg/game.swf is denied due to lack of policy file permissions.


After getting that, it remains in the "connecting" state forever, with no apparent indication that anything has gone wrong, or has completed in any way. Is there some way I can avoid this? I'm unable to turn on bluebox on our clients until this is fixed, which means that we have several players that are unable to play the game.
User avatar
levancho
Posts: 71
Joined: 27 Jun 2011, 16:03

Re: Socket Error -> kill client for ever

Postby levancho » 11 Jul 2012, 13:40

I am cross linking this
http://smartfoxserver.com/forums/viewto ... 19&t=14507

it seems to relate to it, plus I am using air app so there is no browser involved.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error -> kill client for ever

Postby Lapo » 12 Jul 2012, 07:36

@ tgwozdz
Of course you will get those errors in the console if the Server is not running!
The Flash Player is attempting to:

1. load thecrossdomain file
2. establish a socket connection
3. establish an http connection.

All three will fail and error are raised, no doubt about it. You will definitely get those errors outputted in the console. But clients won't see those.
Also you will get the connection event with the success parameter set to false.

If this is not happening we then need you to send us a stripped down code example that we can use to see what you are talking about.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
tgwozdz
Posts: 17
Joined: 22 Jun 2012, 15:36

Re: Socket Error -> kill client for ever

Postby tgwozdz » 12 Jul 2012, 15:49

Of course you will get those errors in the console if the Server is not running!


I realize this, but...

Also you will get the connection event with the success parameter set to false.


The problem is that I am not getting that callback, ever.

If this is not happening we then need you to send us a stripped down code example that we can use to see what you are talking about.


Here's some sample code that reproduces this for me:

Code: Select all

package
{
   import com.bit101.components.HBox;
   import com.bit101.components.PushButton;
   import com.bit101.components.Window;
   import com.smartfoxserver.v2.SmartFox;
   import com.smartfoxserver.v2.core.SFSEvent;
   
   import flash.display.Sprite;
   import flash.display.StageAlign;
   import flash.display.StageScaleMode;
   import flash.events.Event;
   
   public class SmartfoxBugRepro extends Sprite
   {
      private var mSfs:SmartFox;
      
      private var mConnectButton:PushButton;
      private var mDisconnectButton:PushButton;
      
      public function SmartfoxBugRepro()
      {
         stage.scaleMode = StageScaleMode.NO_SCALE;
         stage.align = StageAlign.TOP_LEFT;

         var window:Window = new Window(stage, 0, 0, "Test Client");
         window.width = 300;
         window.height = 100;
         
         var hbox:HBox = new HBox(window, 10, 10);
         mConnectButton = new PushButton(hbox, 0, 0, "Connect", ConnectClickedCB);
         mDisconnectButton = new PushButton(hbox, 0, 0, "Disconnect", DisonnectClickedCB);
         mDisconnectButton.enabled = false;
      }
      
      private function ConnectClickedCB(event:Event):void
      {
         trace("Connecting to server...");
         
         CreateSmartfoxConnectionObject();
         mSfs.connect("localhost", 9933);
         
         mConnectButton.enabled = false;
      }

      private function DisonnectClickedCB(event:Event):void
      {
         trace("Disconnecting from server...");
         
         if (mSfs != null)
         {
            mSfs.disconnect();
         }
      }
      
      private function CreateSmartfoxConnectionObject():void
      {
         if (mSfs)
         {
            mSfs.disconnect();
            
            mSfs.removeEventListener(SFSEvent.CONNECTION, OnConnection);
            mSfs.removeEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);

            mSfs = null;
         }
         
         mSfs = new SmartFox();
         mSfs.useBlueBox = true;      // Toggle this!
         mSfs.debug = true;
         
         mSfs.addEventListener(SFSEvent.CONNECTION, OnConnection);
         mSfs.addEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);

         trace("SmartFox API: " + mSfs.version);
      }
      
      private function OnConnection(event:SFSEvent):void
      {
         trace("OnConnection.  Success: " + event.params.success);
         
         if (event.params.success)
         {
            mDisconnectButton.enabled = true;
         }
         else
         {
            mConnectButton.enabled = true;
         }
      }
      
      private function OnConnectionLost(event:SFSEvent):void
      {
         trace("OnConnectionLost.  Reason: " + event.params.reason);
         mDisconnectButton.enabled = false;
         mConnectButton.enabled = true;
      }
   }
}


This uses just the SFS API, and MinimalComps (http://code.google.com/p/minimalcomps/d ... 0_9_10.swc).

When I run this locally, it behaves as expected, and I get all the events I should be getting. But as soon as I put it on a web server, and hit it from there, I no longer get the connection failed event. Instead, I get an uncaught security exception.

Code: Select all

Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://dev.foo.com/test/dynamic/tomg/bin-debug/SmartfoxBugRepro.swf cannot load data from http://localhost:8080/BlueBox/BlueBox.do.
   at com.smartfoxserver.v2.bitswarm.bbox::BBClient/getLoader()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/bbox/BBClient.as:231]
   at com.smartfoxserver.v2.bitswarm.bbox::BBClient/sendRequest()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/bbox/BBClient.as:224]
   at com.smartfoxserver.v2.bitswarm.bbox::BBClient/connect()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/bbox/BBClient.as:114]
   at com.smartfoxserver.v2.bitswarm::BitSwarmClient/connect()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:252]
   at com.smartfoxserver.v2::SmartFox/handleConnectionProblem()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/SmartFox.as:1935]
   at com.smartfoxserver.v2::SmartFox/onSocketSecurityError()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/SmartFox.as:1790]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at com.smartfoxserver.v2.bitswarm::BitSwarmClient/onSocketSecurityError()[/Users/Paolo/gotoAndPlay/gotoAndPlay/SmartFoxServer2X/API/AS3/src/com/smartfoxserver/v2/bitswarm/BitSwarmClient.as:454]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at flash.net::Socket/onTimeout()
   at flash.utils::Timer/_timerDispatch()
   at flash.utils::Timer/tick()


Could you please verify that you get the same behaviour? If so, is there a way to avoid this, and get a proper connection failure in this case?

Thanks!
tgwozdz
Posts: 17
Joined: 22 Jun 2012, 15:36

Re: Socket Error -> kill client for ever

Postby tgwozdz » 16 Jul 2012, 14:45

Hey Lapo,

Have you had a chance to look at this yet? Or reproduce it locally? Is there anything I can do to avoid this error?

Thanks!
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error -> kill client for ever

Postby Lapo » 16 Jul 2012, 16:33

Hi,
yes and no.
Yes we can reproduce the problem in one case, when the client is on Server1 attempting to access Server2 which is down. In this case unfortunately there doesn't seem to be a way around it, unless you avoid using the BlueBox.

During the connection there is one problem:
- Flash attempts to retrieve policy from Server2:843, fails (master socket policy)
- Flash attempts to retrieve policy from Server2:9933, fails, fires a Sandbox violation error, 2048
- API catch the error and attempt the http connection via BlueBox
- Flash attempts to retrieve policy via HTTP from Server2:8080, fails, but no error event is ever generated!

This scenario doesn't apply if you run locally, standalone player, in Flash/Flex IDE or live on the same server.

During the gazillion tests we have done we have notice a minor issue with an unhandled error 2048 in the BlueBox code but it doesn't change anything. Even when the event is unhandled the API work correctly. And after fixing this thing the problem remains in the scenario I have explained, which I think is your situation.

If you are running several servers and you want to direct the client to a specific one and avoid an instance that is down you might want to use a different approach by storing which server is currently live in a database and serving the information to the client prior to the connection.

Testing the availability of socket from Flash is unreliable due to the policy request behind the scenes and the related security mechanism. In other words it's not just possible to ping a server in order to see if it's alive or not. At least not with the double automatic http failover.

Bottom line:
- turn off the BlueBox acces or...
- use the system I proposed

hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
Nhan
Posts: 1
Joined: 26 Nov 2014, 05:04

Re: Socket Error -> kill client for ever

Postby Nhan » 26 Nov 2014, 12:50

Hello ,
I had the same issue when developing a game for Android & iOS, The issue happened when client app was being working and Server was closed, and start. Client app couldn't connect to server anymore.

However can fix it at client side. Following is the solution.

I defined a singletone class, it is called GameManager.

Code: Select all

      public static class GameManager {
                        private static var _globalSFS:SmartFox = null;
                     public function GameManager () {
            // constructor code
         }
         public static function setSFSDestroy() {
               if(_globalSFS!= null) 
               {
                  _globalSFS.disconnect();
               }
               _globalSFS=null;
         }
                      //-----------------------------------------
         public static function getSFSInstance(): SmartFox  {
            // Singletone instance
            if(_globalSFS== null) 
            {
               _globalSFS = new SmartFox();
               trace("Create new Smartfox instance")
                                   
            }
                     
         return _globalSFS;
              }
                }
                //-----------------------------------------


In other classes, we can use call getSFSInstance() to get SmartfoxServer2X client object.

And you can create a function for connect to solve the problem as follow:
private static var sfs:SmartFox = null;

Code: Select all

    public function  InitConnect():void
   {
         GameManager.setSFSDestroy();
    sfs = null;
    sfs = GameManager.getSFS();
    sfs.addEventListener(SFSEvent.CONNECTION, OnConnected);
        sfs.addEventListener(SFSEvent.CONNECTION_LOST, onConnectionLost);
         sfs.addEventListener(SFSEvent.CONNECTION_RESUME, onConnectionResume);
         sfs.addEventListener(SFSEvent.CONNECTION_RETRY, onConnectionRetry);
         sfs.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConnectionLoadFailed);
         sfs.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, onConfigSucccess);
     
          sfs.LoadConfig("YourConfig.xml");
    }
   
   private function OnConnected(e:SFSEvent) : void
   {
        trace("Connect to server succeed");
   }
  private function onConnectionLost(e:SFSEvent) : void
   {
        trace("Connect to server was lost");
   }


When server is restart, client app try to do InitConnect() again, it is passed the problem be cause you setSFSDestroy() before doing the next things.

Good Luck.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error -> kill client for ever

Postby Lapo » 27 Nov 2014, 14:40

Nhan wrote:Hello ,
I had the same issue when developing a game for Android & iOS, The issue happened when client app was being working and Server was closed, and start. Client app couldn't connect to server anymore.


Yes this is expected, because the server keeps track of disconnected sessions and waits for them to reconnect and start from the point they left. If you kill the server itself, all this data is lost and therefore the client won't be able to use the reconnection system.

It will have to start a new connection from scratch.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 64 guests