Handling Reconnection Based on Ping and Disabling Auto-Reconnect in SmartFoxServer

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Post Reply
eiquy3
Posts: 9
Joined: 21 Oct 2021, 05:42

Handling Reconnection Based on Ping and Disabling Auto-Reconnect in SmartFoxServer

Post by eiquy3 »

Hey,
I am currently using SmartFoxServer v2.19 with Unity and I am facing a few issues related to reconnection and disconnection. I am trying to handle reconnection based on ping received every 2 seconds. So, if no ping is received every 2 seconds, the client will disconnect itself and try to log in again.

I am facing some issues to accomplish this.

1. On disconnection, SmartFoxServer is trying to reconnect automatically. I am not sure if this is because of HRC+ or anything else but because of this, I am not able to reconnect manually. I want to know how I can disable this auto-reconnect feature or how can I keep both?

2. On disconnection, even when I am not in play mode, I am getting this log every second:

Code: Select all

[SFS - WARN] You are not connected. Request cannot be sent: Sfs2X.Requests.PingPongRequest
UnityEngine.Debug:Log (object)
Sfs2X.Logging.Logger:Log (Sfs2X.Logging.LogLevel,string)
Sfs2X.Logging.Logger:Warn (string[])
Sfs2X.SmartFox:Send (Sfs2X.Requests.IRequest)
Sfs2X.Util.LagMonitor.DefaultLagMonitor:OnPollEvent (object,System.Timers.ElapsedEventArgs)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()


This happens even when I am disconnecting the SFS instance manually onApplicationQuit().
Here is the code how I am doing it.

Code: Select all

void OnApplicationQuit()
        {
            if (sfsInstance != null && sfsInstance.IsConnected)
                sfsInstance.Disconnect();
           
            Debug.Log("is connected "+sfsInstance.IsConnected);
        }

Any help or guidance on these issues would be greatly appreciated.

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

Re: Handling Reconnection Based on Ping and Disabling Auto-Reconnect in SmartFoxServer

Post by Lapo »

Hi,
if you want to manage disconnections with your own custom logic it's best to turn off the HRC, to avoid conflicts.
Turn it off via AdminTool > Zone Configurator. More on this in the docs:
http://docs2x.smartfoxserver.com/Develo ... tion-phase (see the bottom section regarding HRC)

When you start a new connection make sure to remove the previous event listeners, then create a new SmartFox() object and apply the new event handlers.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
eiquy3
Posts: 9
Joined: 21 Oct 2021, 05:42

Re: Handling Reconnection Based on Ping and Disabling Auto-Reconnect in SmartFoxServer

Post by eiquy3 »

Thanks Lapo for the response. After disabling HRC My disconnection logic is working fine. This warning log is still persistent. Do you why I am getting this log every second when even when I am not in play mode in unity?

Code: Select all

[SFS - WARN] You are not connected. Request cannot be sent: Sfs2X.Requests.PingPongRequestUnityEngine.Debug:Log (object)
Post Reply