Reconnection system issues

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

Moderators: Lapo, Bax

M-D
Posts: 13
Joined: 24 Oct 2012, 09:13

Reconnection system issues

Postby M-D » 24 Oct 2012, 15:05

I'm currently trying to implement the reconnection system in SmartFoxServer 2x (2.3.0).
I'm having both issues with the Flash and the Java client library.

I set the reconnection time to 60 seconds in the zone xml file.

Basically I setup some logging on both the client and the server, telling me when the CONNECTION_RETRY and CONNECTION_RESUME events are triggered.
I then connect with a java client to the server, make sure it's connected and then unplug my network cable.

After a while I get the following:

Code: Select all

56248 [New I/O client worker #1-1] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: An existing connection was forcibly closed by the remote host
56248 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnError to 1 listeners
56249 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event ioError to 1 listeners
56249 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnDisconnect to 1 listeners
56249 [New I/O client worker #1-1] INFO sfs2x.client.bitswarm.BitSwarmClient - Attempting reconnection in 1000 msec
56249 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event reconnectionTry to 1 listeners
56249 [New I/O client worker #1-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event connectionRetry to 1 listeners
[TEST] Connection retry: connectionRetry [ sfs2x.client.SmartFox@41f6321]
[TEST] getReconnectionSeconds(): 60
56351 [Timer-1] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: null
56351 [Timer-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnError to 1 listeners
56351 [Timer-1] INFO sfs2x.client.core.EventDispatcher - Dispatching event ioError to 1 listeners


The [TEST] bits are what I log. All of this happens within a few seconds of each other.

Then I plug the cable back in, but nothing happens. If I try to do something I get the following error:

Code: Select all

70287 [AWT-EventQueue-0] WARN sfs2x.client.SmartFox - You are not connected. Request cannot be sent: sfs2x.client.requests.ExtensionRequest@889ec59


I can see the connection retry event is triggered, but nothing happens (not when I plug it back it, or when I wait 60 seconds).
I also noticed that it's dispatching an event on 'OnDisconnect', but I don't seem to get this (even though I listen to CONNECTION_LOST).

The same happens with our Flash client (although there I do get the CONNECTION_LOST event triggered, slightly after the CONNECTION_RETRY event is triggered).

Am I doing something wrong? Or is there are bug in the client libraries?

(I already made sure both client libraries are the latest from the download page)
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Reconnection system issues

Postby rjgtav » 24 Oct 2012, 20:18

Hi,
You can't unplug the cable, as that will kill the connection completely. For testing the reconnection system, what you can do is to call the killConnection() function from the SmartFox instance on the AS3 client API, which simulates an abrupt disconnection, like the ones you get when your internet connection fails.
There's also a corresponding method on the Java Client API
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
M-D
Posts: 13
Joined: 24 Oct 2012, 09:13

Re: Reconnection system issues

Postby M-D » 29 Oct 2012, 09:40

Hello,

So if I understand this correctly, this system wont work when you lose your WiFi or 3G connection for example?

And I still don't understand why I don't get the CONNECTION_LOST event in the java client, is this a bug?

// Edit
Okay I just updated the JAVA client library (1.0.4), now the following happens:

Code: Select all

110143 [New I/O  worker #1] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnDisconnect to 1 listeners
110143 [New I/O  worker #1] INFO sfs2x.client.bitswarm.BitSwarmClient - Attempting reconnection in 1000 msec
110143 [Thread-4] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: An existing connection was forcibly closed by the remote host
110143 [New I/O  worker #1] INFO sfs2x.client.core.EventDispatcher - Dispatching event reconnectionTry to 1 listeners
110143 [New I/O  worker #1] INFO sfs2x.client.core.EventDispatcher - Dispatching event connectionRetry to 1 listeners
[TEST] Connection retry: connectionRetry [ sfs2x.client.SmartFox@1a8fa0d1]
[TEST] getReconnectionSeconds(): 60
110143 [Thread-4] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnError to 1 listeners
110145 [Thread-4] INFO sfs2x.client.core.EventDispatcher - Dispatching event ioError to 1 listeners
110262 [Thread-8] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: null
110262 [Thread-8] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnError to 1 listeners
110262 [Thread-8] INFO sfs2x.client.core.EventDispatcher - Dispatching event ioError to 1 listeners
128192 [AWT-EventQueue-0] WARN sfs2x.client.SmartFox - You are not connected. Request cannot be sent: sfs2x.client.requests.ExtensionRequest@10f1f34a
130158 [AWT-EventQueue-0] WARN sfs2x.client.SmartFox - You are not connected. Request cannot be sent: sfs2x.client.requests.ExtensionRequest@50f800db

(The last two errors are when I try to send a command.)

I still don't get a CONNECTION_LOST, I do get the connection retry. However nothing happens (I also don't get a CONNECTION_LOST after the 60 seconds pass).
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Reconnection system issues

Postby Lapo » 29 Oct 2012, 13:52

There are at least 3 questions here, so we need to address them separately.

1) How to use HRC: the main problem is how to trigger the disconnection. Unexpected drops can be due to all sorts of reasons and it's not easy to emulate them. They can be caused by your ISP, a temp network failure, a drop in any of the routers through your netwrok path etc...

Unplugging the network cable doesn't seem to work as a test. When you unplug it none of the current connections should be closed because technically there's no available network, therefore the 4-way TCP close cannot be performed. After some time the OS might get rid of those connections because they are idle but it could take a long time.

We provide a test method call killConnection() in the API which allows to emulate an unexpected disconnection and triggering the system.

So if I understand this correctly, this system wont work when you lose your WiFi or 3G connection for example?

In general it should work.
3G connections are probably more tricky because they can create those "ghost connections. Technically they are incomplete TCP close that result in a connection not completely closed (CLOSE_WAIT state). In this case the system won't trigger because the OS doesn't recognize the client disconnection.

2/3) Java and Flash API issues
It would be best if you could post a report for each problem in the respective forums so that those who are in charge of the API can take a look.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
M-D
Posts: 13
Joined: 24 Oct 2012, 09:13

Re: Reconnection system issues

Postby M-D » 29 Oct 2012, 14:12

Thanks for your reply Lapo.
I posted the java problem in the java client subforum.

I have another question for the HRC: is it (technically) capable of reconnecting when switching from 3G to WiFi?

For example: we have a game on iPad, the user is playing a game and leaves his house or loses WiFi connection after which his 3G connection kicks in.
Is HRC capable of handling this type of disconnect / reconnect?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Reconnection system issues

Postby Lapo » 02 Nov 2012, 13:50

It has never been tested in this context. In think it is possible.
We'll look into it and see if already works.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 64 guests