Prevent time out on smartfox client

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

songsong
Posts: 2
Joined: 22 Jul 2008, 09:00

Prevent time out on smartfox client

Postby songsong » 02 Dec 2008, 11:10

Hi,

My smartfoxclient keeps getting disconnect from the server. I read somewhere that I can send an empty extension command to prevent that, but I still got disconnect despite having a timer task to send that command every 30 secs.

Below the is command that I used to send the empty command.

sfsClient.sendXtMessage( "", "" , {} );

Please advise what is the correct method tho prevent timeout in case the user really idles for too long. Thanks!
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 05 Dec 2008, 01:06

There is a command on SFS that allows you to send very small packages to the server:
smartfox.roundTripBench();
and
smartfox.onRoundTripResponse = function(elapsed:Number)

Supposedly it should prevent users from getting disconnected, but I think Lapo removed that option on the latest versions. The only approach I was able to use is set the MaxUserIdleTime to a very high number on the config file:

Code: Select all

<MaxUserIdleTime>9000</MaxUserIdleTime>

Ever since SFS Pro 1.6.0 the ghost connections are close to 0 so I haven't had any problems with the infamous "username taken" so far.

If there is an alternative option I'd also like to know :)
SELECT * FROM users WHERE clue > 0
0 rows returned.
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 05 Dec 2008, 07:16

mistermind:
ATTENTION: the roundTripBench won't work as a keepalive

songsong
sfsClient.sendXtMessage( "", "" , {} );


This is not correct the first and second param should be non null or non empty strings.
Something like:

Code: Select all

sfsClient.sendXtMessage( "myExt", "myCmd" , {} );


Of course you can avoid to implement any method for the myCmd request in your server side extension.The simple act of sending a proper extension request will act as a keep alive.
Lapo
--
gotoAndPlay()
...addicted to flash games
Blarg
Posts: 12
Joined: 11 Jun 2009, 06:23

Postby Blarg » 11 Jun 2009, 06:46

Hi!

Any way to do this with smartfox server BASIC ?

I developped a game with the lite version, before switching to BASIC recently, and I'm disappointed to see that the roundTripBench won't do the trick anymore. The thing is, unless using the PRO version, you can override the problem by setting a very high maxIdleTime, but if a player happens to disconnect by accident, he'll need to wait a long time before the server realize he isn't connected anymore...

So it's sort of a dead end. Furthermore, the game features automatic reconnection after the connection is lost during a game, and that isn't possible at all without a small max idle time that can be renewed frequently, or the pro version.

I've tried the
sfsClient.sendXtMessage( "", "" , {} );
trick but it doesn't work either, once again because I'm not using the PRO version I guess...

An empty private message to myself doesn't seem to work either.
Like this: smartfox.sendPrivateMessage("",smartfox.myUserId);
Well. It does work... but only when I'm logged in. I can still get kicked when I'm connected and I must enter my login info.

So.. that sums it up... I'm pretty puzzled right now. Geting the PRO version is not an option either right now.

Thanks in advance
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 11 Jun 2009, 08:21

The thing is, unless using the PRO version, you can override the problem by setting a very high maxIdleTime, but if a player happens to disconnect by accident, he'll need to wait a long time before the server realize he isn't connected anymore...

No won't need to wait a long time, the maxIdleTime doesn't block a reconnection. If the user is disconnected he can immediately reconnect again.
Setting a high maxIdleTime is actually the way to go.
Lapo

--

gotoAndPlay()

...addicted to flash games
Blarg
Posts: 12
Joined: 11 Jun 2009, 06:23

Postby Blarg » 11 Jun 2009, 15:54

Oh... thanks!

Is that a feature of smartfox basic that smartfox lite doesn't have? Because I was stumped by this while using lite, hence why I had to resolve to set a short maxIdleTime. And I read somewhere that only the pro version had the capacity to override a ghost connection upon reconnection.

I haven't tested with a high maxIdleTime yet, I will let you know the results.
Blarg
Posts: 12
Joined: 11 Jun 2009, 06:23

Postby Blarg » 11 Jun 2009, 16:43

I've tested now, and it works indeed. Thanks again for the support.
Blarg
Posts: 12
Joined: 11 Jun 2009, 06:23

Postby Blarg » 14 Jun 2009, 23:44

Hmmm, Seems to be some part of the problem left. The server does not look like it recognizes a disconnection if it happens by accident (actual problems with the connection of the user). I had an user who lost his connection to the game, and wasn't able to log in again, getting instead a message saying that his username was already taken. Which was exactly the reason why I decided to use a short maxIdleTime to begin with.

Is there a workaround for this? I figure that's where the max idle time comes in handy (as I did figure before), but then that brings me back to my initial problem...

EDIT: I've consulted the smartfox docs, and it seems there is no magical solution since I use smartfox basic and not pro (thus no "force login" option.. right?). However, would "maxSocketIdleTime" work to eliminate ghost connections? I suppose not though, since I guess smartfox also sees the user as still logged in.
Godai
Posts: 29
Joined: 23 Jan 2009, 12:14

Postby Godai » 25 Jun 2009, 08:24

ATTENTION! This is not true.
I just made a simple test and calling a non-existing extension will not save you from timeout.

Just add this function to your extensions handleRequest handler:

Code: Select all

if (cmd == "keepAlive")
{
   trace("Got keepalive from client!");
   return;
}


and call it from your actionscript in a timer just before timout (i.e. on 5 minute timeout just call it every 4,9 mins)

I have a simple example to prove this. Smartfox version is 1.6.6
Dest987
Posts: 12
Joined: 21 Apr 2009, 01:37

Postby Dest987 » 14 Jul 2009, 22:34

force login option: Since SmartFoxServer PRO 1.6.3 we have introduced an extra "force login" flag in the server side login() method that forces the sudden disconnect of a previous user when the same client is logging in again.


Is there a way to call force login from the iPhone client/an easy way to add it? Or do you have to do it through a server side extension?
User avatar
Ross Przybylski
Posts: 70
Joined: 24 Jan 2008, 03:56
Contact:

Postby Ross Przybylski » 17 Jul 2009, 01:28

It's time I join the fun of this forum- server disconnects have been one of my most frustrating issues. Before I switched from SFS Basic to SFS Pro (which rocks btw) my solution was to ping the server by having users send private messages to themselves every 3 seconds which were intercepted by the handler and never actually shown to the user.

This was all fine and good until I realized that users weren't able to see the private messages they sent to other users- only the ones they got from other users.

Now that I am on Pro, I've implemented the extension ping solution, which seems to work fine, however, my goal was to eliminate the need for pinging the server by simply extending the max user idle time.

I am noticing definite issues with the max user idle time- which I have set to 10800 (3hrs). After having played with it the past couple days, the behavior seems to be quite sparadic. In some cases, users will stay logged in for awhile - even after I unplug the lan cord- their username will remain for upwards of an hour before the ghost connection is detected (especially if that connection was sustaining a room). In other cases, a user with a stable connection will just suddenly drop out before the max idle time (maybe after 5-10 minuts or so of sitting in the lobby or a game room).

I've been able to handle the ghost connection problems using the force login option (so if you drop out and your name lingers, you can still get back online).

But, since I can't currently trust the max idle time to keep users online, I've gone back to pinging the server with the sendXt function. Originally, I'd ping the server every 3 seconds because my max idle time used to be only 30 seconds or so to prevent the ghost user issue. Now I thought'd it be best in the interest of bandwidth to spread it out a bit- so I only send it every 5 minutes. However- I'm still noticing that this is not a frequent enough ping to guarantee the server connection will be maintained.

So, at last, my question is- what is the best way to ensure a connection to the server remains for a user who is logged in? How frequent do my server pings need to be to be safe and still be at a reasonable bandwidth usage?
Dest987
Posts: 12
Joined: 21 Apr 2009, 01:37

Postby Dest987 » 17 Jul 2009, 02:03

How did you use the force login option? Is it in the flash API/iPhone API? Do you have to do it through extensions? If so how do you get the extension login behavior to mimic the normal login behavior + the force option? Sorry if any of these questions are stupid, I haven't looked at the extension stuff much.
User avatar
Ross Przybylski
Posts: 70
Joined: 24 Jan 2008, 03:56
Contact:

Postby Ross Przybylski » 17 Jul 2009, 02:14

Dest987 wrote:How did you use the force login option? Is it in the flash API/iPhone API? Do you have to do it through extensions? If so how do you get the extension login behavior to mimic the normal login behavior + the force option? Sorry if any of these questions are stupid, I haven't looked at the extension stuff much.


Yes, the force login option can only be implemented via server side extension. If you want to use it, you'll need to write an extension that handles the loginRequest internal event. Unfortunately, if you use a custom login extension, you will also need to change your game client to handle logins via the extension reponse, and not the default SFS login listener.

Since you mentioned that you haven't looked into extensions yet, I would highly recommend you check out the SFS extension tutorials in the docs section. The login is one of the first extensions covered- and the documentation is very good and easy to follow. I know that writing extensions can seem like a daunting task, I was in the same boat before I finally went ahead and looked through the documentation and realized they can be written quickly in ActionScript 1.0 and offer incredible development power. Take a look at these first and if you still have questions, I'd be happy to help out.
Blarg
Posts: 12
Joined: 11 Jun 2009, 06:23

Postby Blarg » 17 Jul 2009, 02:37

Ross, your input confirms a lot of my observations. I personally can't afford to go Pro though, so it's a bit complicated. However I'm not sure what you mean here:

Ross Przybylski wrote:Before I switched from SFS Basic to SFS Pro (which rocks btw) my solution was to ping the server by having users send private messages to themselves every 3 seconds which were intercepted by the handler and never actually shown to the user.

This was all fine and good until I realized that users weren't able to see the private messages they sent to other users- only the ones they got from other users.


How is this a problem? That's the method I am using too for pinging, and it seems to do the job even when there is only one user connected (which means the ping can not come from messages sent by others). smartfox.onPrivateMessage isn't fired, but the connection doesn't expire either.
User avatar
Ross Przybylski
Posts: 70
Joined: 24 Jan 2008, 03:56
Contact:

Postby Ross Przybylski » 17 Jul 2009, 03:01

In my case, I have the onPrivateMessage event handler function setup to display the message for the appropriate context (which was different depending on lobby or game). When I was using the private message to ping the server, I had this handler function filter out any messages that were sent by the currently connected user (so they wouldn't see their own pm's to themselves coming through). Since the onPrivateMessage is also fired for the sender of private messages (not just the recipient) this had the effect of also filtering out private messages that the user sent to other users - these messages would still go out, but I wouldn't see the Ross PM -> Blarg in my lobby or chat pane.

The onPrivateMessage message event doesn't provide a recipient parameter, only the sender, so there was no direct/simple way to compare who the PM was sent to (which is what I really should have been comparing). Granted, there are several ways I could have worked around this, such as appending my own PM's to chat in the PM send function or sending a coded message that I could scan for in the onPrivateMessage handler. I opted for the sendXT message instead because it was, in my opinion, the cleaner solution to have a separate function dedicated to pinging the server vs. using PM as a workaround.

When I was using Basic, PM was the best workaround since it has the lowest bandwidth usage and roundTripBench does not work and sendXT does not work without valid extension setup (as others have mentioned).

Actually- I think it would help a great many users if the smartFoxClient had a separate function dedicated to pinging the server and a separate SFSEvent for receiving the ping. Future feature, perhaps?

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 26 guests