Auto reconnect after kickUser()

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Ulnari
Posts: 18
Joined: 20 Aug 2008, 15:17

Auto reconnect after kickUser()

Postby Ulnari » 29 Sep 2009, 15:05

Hi,

I am using SFS 1.6.6

In my server extension, I am using ExtensionHelper.kickUser() to remove a user from the room, which works as expected. SFS Client debug out:

Code: Select all

[ RECEIVED ]: <msg t='sys'><body action='dmnMsg' r='0'><user id='1' /><txt><![CDATA[Game has stopped]]></txt></body></msg>, (len: 108)
[ RECEIVED ]: <msg t='sys'><body action='userGone' r='5'><user id='0' /></body></msg>, (len: 71)
[ RECEIVED ]: <msg t='sys'><body action='uCount' r='5' u='1' s='0'></body></msg>, (len: 66)


Client dispatches the onConnectionLost event then.

Problem is, after a few seconds (~5) the client reconnects using the BlueBox. SFS debug output says:
Socket connection failed. Trying BlueBox
[ Send ]: sfsHttp=connect


I want BlueBox fallback only in case my connect attempt fails. I don't want a client to reconnect on it's own, after I kick a user.

How can I disable this behavior?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 30 Sep 2009, 14:49

Hi,
if the client is disconnected by the server it will receive an onConnectionLost event and that's it. There's no automatic reconnection unless the client attempts to reconnect by himself.

This is possible and perfectly legal. A kick is simply a warning for the User to stop misbehaving. You will need to ban a User in order to prevent him from connecting for some time.
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 30 Sep 2009, 14:51

Problem is, after a few seconds (~5) the client reconnects using the BlueBox. SFS debug output says:

I can't reproduce this.
Reconnecting after a kick always uses sockets, if they are available
Lapo

--

gotoAndPlay()

...addicted to flash games
Ulnari
Posts: 18
Joined: 20 Aug 2008, 15:17

Postby Ulnari » 30 Sep 2009, 20:28

Lapo wrote:
Problem is, after a few seconds (~5) the client reconnects using the BlueBox. SFS debug output says:

I can't reproduce this.
Reconnecting after a kick always uses sockets, if they are available


You didn't really try it out, did you?

Just grab the AS3 example "template_AS3", turn client debug an and connect to a room with this extension:

Code: Select all

import it.gotoandplay.smartfoxserver.data.*;
import it.gotoandplay.smartfoxserver.extensions.*;
import it.gotoandplay.smartfoxserver.lib.ActionscriptObject;
import it.gotoandplay.smartfoxserver.events.InternalEventObject;

import org.json.JSONObject;

public class ConnectionTest extends AbstractExtension
{
   public void init()
   {
      trace("Extension initialized");   
   }
   
   public void destroy()
   {
      trace("Extension destroyed");
   }
   
   public void handleRequest(String cmd, ActionscriptObject ao, User u, int fromRoom)
   {
      // Your code here
   }
   
   public void handleRequest(String cmd, String params[], User u, int fromRoom)
   {
      // Your code here
   }
   
   public void handleRequest(String cmd, JSONObject jso, User u, int fromRoom)
   {
      // Your code here
   }
   
   public void handleInternalEvent(InternalEventObject evt)
   {
        String evtName = evt.getEventName();

        if (evtName.equals(InternalEventObject.EVENT_JOIN))
        {
           User user = (User) evt.getObject("user");
           
           ExtensionHelper.instance().kickUser(user, 0, "bye");
        }
   }
}



client gets immediately disconnected, but tries 5 secs later on it's own to reconnect using bluebox (and gets kicked again).
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 01 Oct 2009, 08:39

You didn't really try it out, did you?

Of course I did, otherwise I wouldn't have responded.

The problem here is timing. Now that you showed your code I have more clues.
I am able to reproduce the issue if I kick the user almost immediately while he's still finishing the login/join procedure.

I think it's due to some API flag being set after a while. If the disconnection happens so fast the API believe it's a socket problem and attempt to use the BlueBox.

A delay of 5 seconds (or more) before kicking the user makes everything work correctly.
Lapo

--

gotoAndPlay()

...addicted to flash games
Ulnari
Posts: 18
Joined: 20 Aug 2008, 15:17

Postby Ulnari » 01 Oct 2009, 12:15

Lapo wrote:
You didn't really try it out, did you?

Of course I did, otherwise I wouldn't have responded.

Sorry, couldn't resist.

Actually I want to thank you for your help.

The code for immediate kick is just an example so that you can reproduce the behavior. In my application the user isn't kicked at the moment he joins. He is kicked after he has played a game against another user, which takes 5-10 *minutes*, and the other user has left.

So the client API re-connects via bluebox automatically even if there was a solid connection for minutes.
Ulnari
Posts: 18
Joined: 20 Aug 2008, 15:17

Postby Ulnari » 06 Oct 2009, 11:43

Lapo, did you reproduce the behavior? It seems independend of the amount of time the user was logged in.
blindgoatia
Posts: 8
Joined: 02 Jul 2009, 18:29

Same problem

Postby blindgoatia » 04 Aug 2010, 20:07

Lapo-

We are experiencing the exact same symptoms as Ulnari described. We wait several minutes after the user logs in to kick them. After approximately five seconds after they have been kicked, the user starts to connect again using BlueBox.

Here is some client output for the kicked user:

Connection Lost
.
. (approx. 5 seconds lapses)
.
Socket connection failed. Trying BlueBox
[ Send ]: sfsHttp=connect


Any ideas or updates on this?

Thanks,
-- blindgoat
blindgoatia
Posts: 8
Joined: 02 Jul 2009, 18:29

Update

Postby blindgoatia » 04 Aug 2010, 20:26

After further testing, I discovered something else.

The auto-reconnecting using BlueBox ONLY occurs when the client is running in the Flash standalone player. When the client is in a browser, it never automatically tries to reconnect after a kick.

I am using SFS 1.6.8 and Flash Player 10,1,53,64.

Thanks!
-- blindgoat

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 19 guests